簡體   English   中英

Heroku上的Rails:ActiveRecord :: StatementInvalid,重置和遷移不起作用

[英]Rails on Heroku: ActiveRecord::StatementInvalid, resetting and migrating doesn't work

嘗試打開我剛剛推送到heroku的應用程序時出現以下錯誤,本地一切正常。 我已經嘗試使用rake db:reset,pg:reset,db:migrate刪除和重新推送,並且所有表都具有復數名稱。 每個步驟后我也都重新啟動了。數據庫顯示在Heroku儀表板中。 任何幫助將不勝感激,我希望將其用作即將進行的項目的概念證明,但與此同時,我已經徹底碰壁了!

ActiveRecord :: StatementInvalid(PGError:錯誤:關系“帖子”不存在

我基於博客教程構建了該應用程序,並且運行良好,此后我又添加了2個其他表格(在其他教程之后)並設置了使用Nokogiri的rake任務,但我不知道該怎么破壞鏈接到職位表?

完整的在這里: https : //github.com/mwhammond/futurebot

訪問該應用后的日志詳細信息

2013-05-08T09:55:12.832527+00:00 app[web.1]: Started GET "/" for 155.198.164.33
at 2013-05-08 09:55:12 +0000
2013-05-08T09:55:12.925179+00:00 app[web.1]: Processing by PostsController#index
 as HTML
2013-05-08T09:55:13.026158+00:00 app[web.1]: ):
2013-05-08T09:55:13.024635+00:00 app[web.1]: Completed 500 Internal Server Error
 in 99ms
2013-05-08T09:55:13.026158+00:00 app[web.1]:              ORDER BY a.attnum
2013-05-08T09:55:13.025910+00:00 app[web.1]:
     ^
2013-05-08T09:55:13.025910+00:00 app[web.1]:
2013-05-08T09:55:13.026158+00:00 app[web.1]:
**2013-05-08T09:55:13.025910+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGE
rror: ERROR:  relation "posts" does not exist**
2013-05-08T09:55:13.025910+00:00 app[web.1]:              WHERE a.attrelid = '"p
osts"'::regclass
2013-05-08T09:55:13.025910+00:00 app[web.1]: LINE 5:              WHERE a.attrel
id = '"posts"'::regclass
2013-05-08T09:55:13.026158+00:00 app[web.1]:
2013-05-08T09:55:13.025910+00:00 app[web.1]:                      pg_get_expr(d.
adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
2013-05-08T09:55:13.026158+00:00 app[web.1]:   app/controllers/posts_controller.
rb:5:in `index'
2013-05-08T09:55:13.025910+00:00 app[web.1]:               FROM pg_attribute a L
EFT JOIN pg_attrdef d
2013-05-08T09:55:13.025910+00:00 app[web.1]:                AND a.attnum > 0 AND
 NOT a.attisdropped
2013-05-08T09:55:13.025910+00:00 app[web.1]:                 ON a.attrelid = d.a
drelid AND a.attnum = d.adnum

帖子模型:

class Post < ActiveRecord::Base
  attr_accessible :content, :contentSummary, :image, :link, :score, :title, :tags_attributes

  has_many :comments
  has_many :tags

  accepts_nested_attributes_for :tags, :allow_destroy => :true,
  :reject_if => proc { |attrs| attrs.all? { |k,v| v.blank?} }

end



posts Controller:

class PostsController < ApplicationController
  # GET /posts
  # GET /posts.json
  def index
    @posts = Post.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @posts }
    end
  end

  # GET /posts/1
  # GET /posts/1.json
  def show
    @post = Post.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @post }
    end
  end

  # GET /posts/new
  # GET /posts/new.json
  def new
    @post = Post.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @post }
    end
  end

  # GET /posts/1/edit
  def edit
    @post = Post.find(params[:id])
  end

  # POST /posts
  # POST /posts.json
  def create
    @post = Post.new(params[:post])

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render json: @post, status: :created, location: @post }
      else
        format.html { render action: "new" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /posts/1
  # PUT /posts/1.json
  def update
    @post = Post.find(params[:id])

    respond_to do |format|
      if @post.update_attributes(params[:post])
        format.html { redirect_to @post, notice: 'Post was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  def upVote
    @post = Post.find(params[:id])
    @post.increment!(:score)
    format.html { redirect_to posts_url }
    format.json { head :no_content }
  end


  # DELETE /posts/1
  # DELETE /posts/1.json
  def destroy
    @post = Post.find(params[:id])
    @post.destroy

    respond_to do |format|
      format.html { redirect_to posts_url }
      format.json { head :no_content }
    end
  end
end

遷移

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :title
      t.text :content
      t.text :contentSummary
      t.integer :score
      t.string :image
      t.string :link

      t.timestamps
    end
  end
end

heroku rake:db遷移的結果(從cmd復制已刪除首字母)

igrating to CreateComments (20130501205150)
=  CreateComments: migrating =================================================
- create_table(:comments)
OTICE:  CREATE TABLE will create implicit sequence "comments_id_seq" for serial
column "comments.id"
OTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "comments_pkey" f
r table "comments"
  -> 0.0765s
- add_index(:comments, :post_id)
  -> 0.0419s
=  CreateComments: migrated (0.1186s) ========================================

再次重置和遷移后的完整日志

C:\..futurebot>heroku open
Opening warm-eyrie-3091... done

C:\..\code\futurebot>heroku logs
2013-05-08T11:02:50.243561+00:00 heroku[web.1]: State changed from starting to u
p
2013-05-08T11:02:52.475512+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At l
east one process failed to exit within 10 seconds of SIGTERM
2013-05-08T11:02:52.475715+00:00 heroku[web.1]: Stopping remaining processes wit
h SIGKILL
2013-05-08T11:02:54.540425+00:00 heroku[web.1]: Process exited with status 137
2013-05-08T11:03:51.190205+00:00 heroku[api]: Starting process with command `bun
dle exec rake db:migrate` by m.w.hammond@live.co.uk
2013-05-08T11:03:53.139998+00:00 heroku[run.7922]: Awaiting client
2013-05-08T11:03:53.183567+00:00 heroku[run.7922]: Starting process with command
 `bundle exec rake db:migrate`
2013-05-08T11:03:54.361849+00:00 heroku[run.7922]: State changed from starting t
o up
2013-05-08T11:03:59.655214+00:00 heroku[run.7922]: Process exited with status 0
2013-05-08T11:03:59.664971+00:00 heroku[run.7922]: State changed from up to comp
lete
2013-05-08T11:04:06.910562+00:00 app[web.1]: Started GET "/" for 155.198.164.33
at 2013-05-08 11:04:06 +0000
2013-05-08T11:04:07.142491+00:00 app[web.1]: Processing by PostsController#index
 as HTML
2013-05-08T11:04:07.440192+00:00 app[web.1]:   Rendered posts/index.html.erb wit
hin layouts/application (20.8ms)
2013-05-08T11:04:07.579532+00:00 heroku[router]: at=info method=GET path=/ host=
warm-eyrie-3091.herokuapp.com fwd="155.198.164.33" dyno=web.1 connect=1ms servic
e=702ms status=500 bytes=643
2013-05-08T11:04:07.576031+00:00 app[web.1]: Completed 500 Internal Server Error
 in 433ms
2013-05-08T11:04:07.578136+00:00 app[web.1]:   (in /app/app/assets/javascripts/a
pplication.js:15)):
2013-05-08T11:04:07.578136+00:00 app[web.1]:
2013-05-08T11:04:07.578136+00:00 app[web.1]:     155:
2013-05-08T11:04:07.578136+00:00 app[web.1]:     156:
2013-05-08T11:04:07.578136+00:00 app[web.1]:     158: </body>
2013-05-08T11:04:07.578136+00:00 app[web.1]:     159: </html>
2013-05-08T11:04:07.578136+00:00 app[web.1]:   app/views/layouts/application.htm
l.erb:157:in `_app_views_layouts_application_html_erb___482820919685099463_26157
420'
2013-05-08T11:04:07.578463+00:00 app[web.1]:   app/controllers/posts_controller.
rb:7:in `index'
2013-05-08T11:04:07.578136+00:00 app[web.1]:     154:
2013-05-08T11:04:07.578463+00:00 app[web.1]:
2013-05-08T11:04:07.578463+00:00 app[web.1]:
2013-05-08T11:04:07.578136+00:00 app[web.1]:     157: <%= javascript_include_tag
 "application" %>
2013-05-08T11:04:07.578136+00:00 app[web.1]: ActionView::Template::Error (couldn
't find file 'foundation'
2013-05-08T11:04:07.878076+00:00 heroku[router]: at=info method=GET path=/favico
n.ico host=warm-eyrie-3091.herokuapp.com fwd="155.198.164.33" dyno=web.1 connect
=1ms service=30ms status=200 bytes=0
2013-05-08T11:05:06.045135+00:00 app[web.1]: Started GET "/" for 155.198.164.33
at 2013-05-08 11:05:06 +0000
2013-05-08T11:05:06.050046+00:00 app[web.1]: Processing by PostsController#index
 as HTML
2013-05-08T11:05:06.054225+00:00 app[web.1]:   Rendered posts/index.html.erb wit
hin layouts/application (0.0ms)
2013-05-08T11:05:06.070776+00:00 app[web.1]:   (in /app/app/assets/javascripts/a
pplication.js:15)):
2013-05-08T11:05:06.070776+00:00 app[web.1]:
2013-05-08T11:05:06.070776+00:00 app[web.1]: ActionView::Template::Error (couldn
't find file 'foundation'
2013-05-08T11:05:06.070776+00:00 app[web.1]:     154:
2013-05-08T11:05:06.070776+00:00 app[web.1]:     155:
2013-05-08T11:05:06.069069+00:00 app[web.1]: Completed 500 Internal Server Error
 in 18ms
2013-05-08T11:05:06.071057+00:00 app[web.1]:
2013-05-08T11:05:06.070776+00:00 app[web.1]:     156:
2013-05-08T11:05:06.070776+00:00 app[web.1]:     158: </body>
2013-05-08T11:05:06.070776+00:00 app[web.1]:     157: <%= javascript_include_tag
 "application" %>
2013-05-08T11:05:06.070776+00:00 app[web.1]:   app/views/layouts/application.htm
l.erb:157:in `_app_views_layouts_application_html_erb___482820919685099463_26157
420'
2013-05-08T11:05:06.071057+00:00 app[web.1]:   app/controllers/posts_controller.
rb:7:in `index'
2013-05-08T11:05:06.071057+00:00 app[web.1]:
2013-05-08T11:05:06.080969+00:00 heroku[router]: at=info method=GET path=/ host=
warm-eyrie-3091.herokuapp.com fwd="155.198.164.33" dyno=web.1 connect=1ms servic
e=35ms status=500 bytes=643
2013-05-08T11:05:06.070776+00:00 app[web.1]:     159: </html>
2013-05-08T11:05:06.555724+00:00 heroku[router]: at=info method=GET path=/favico
n.ico host=warm-eyrie-3091.herokuapp.com fwd="155.198.164.33" dyno=web.1 connect
=8ms service=6ms status=304 bytes=0
2013-05-08T12:08:30.478683+00:00 heroku[web.1]: Idling
2013-05-08T12:08:34.015063+00:00 heroku[web.1]: Stopping all processes with SIGT
ERM
2013-05-08T12:08:34.927659+00:00 app[web.1]: [2013-05-08 12:08:34] ERROR SignalE
xception: SIGTERM
2013-05-08T12:08:34.927659+00:00 app[web.1]:    /usr/local/lib/ruby/1.9.1/webric
k/server.rb:90:in `select'
2013-05-08T12:08:44.546949+00:00 heroku[web.1]: Error R12 (Exit timeout) -> At l
east one process failed to exit within 10 seconds of SIGTERM
2013-05-08T12:08:44.548790+00:00 heroku[web.1]: Stopping remaining processes wit
h SIGKILL
2013-05-08T12:08:46.665774+00:00 heroku[web.1]: Process exited with status 137
2013-05-08T12:08:46.682414+00:00 heroku[web.1]: State changed from up to down
2013-05-08T12:33:09.786644+00:00 heroku[api]: Starting process with command `bun
dle exec rake db:reset` by m.w.hammond@live.co.uk
2013-05-08T12:33:11.890651+00:00 heroku[run.1452]: Awaiting client
2013-05-08T12:33:11.911563+00:00 heroku[run.1452]: Starting process with command
 `bundle exec rake db:reset`
2013-05-08T12:33:12.849180+00:00 heroku[run.1452]: State changed from starting t
o up
2013-05-08T12:33:18.476989+00:00 heroku[run.1452]: Process exited with status 0
2013-05-08T12:33:18.500279+00:00 heroku[run.1452]: State changed from up to comp
lete
2013-05-08T12:33:28.451763+00:00 heroku[api]: Starting process with command `bun
dle exec rake db:migrate` by m.w.hammond@live.co.uk
2013-05-08T12:33:30.568900+00:00 heroku[run.3481]: Awaiting client
2013-05-08T12:33:30.6172
87+00:00 heroku[run.3481]: Starting process with command `bundle exec rake db:mi
grate`
2013-05-08T12:33:31.364453+00:00 heroku[run.3481]: State changed from starting t
o up
2013-05-08T12:33:36.079923+00:00 heroku[run.3481]: Process exited with status 0
2013-05-08T12:33:36.091667+00:00 heroku[run.3481]: State changed from up to comp
lete
2013-05-08T12:33:42.007923+00:00 heroku[web.1]: State changed from down to start
ing
2013-05-08T12:33:44.023815+00:00 heroku[web.1]: Starting process with command `b
undle exec rails server -p 23102`
2013-05-08T12:33:46.965808+00:00 app[web.1]: DEPRECATION WARNING: You have Rails
 2.3-style plugins in vendor/plugins! Support for these plugins will be removed
in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to
your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-h
as-been-released. (called from <top (required)> at /app/config/environment.rb:5)

2013-05-08T12:33:46.966363+00:00 app[web.1]: DEPRECATION WARNING: You have Rails
 2.3-style plugins in vendor/plugins! Support for these plugins will be removed
in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to
your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-h
as-been-released. (called from <top (required)> at /app/config/environment.rb:5)

2013-05-08T12:33:46.966723+00:00 app[web.1]: DEPRECATION WARNING: You have Rails
 2.3-style plugins in vendor/plugins! Support for these plugins will be removed
in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to
your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release
notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-h
as-been-released. (called from <top (required)> at /app/config/environment.rb:5)

2013-05-08T12:33:49.595740+00:00 app[web.1]: => Booting WEBrick
2013-05-08T12:33:49.595740+00:00 app[web.1]: => Rails 3.2.13 application startin
g in production on http://0.0.0.0:23102
2013-05-08T12:33:49.595740+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-05-08T12:33:49.595740+00:00 app[web.1]: Connecting to database specified by
 DATABASE_URL
2013-05-08T12:33:49.595740+00:00 app[web.1]: => Call with -d to detach
2013-05-08T12:33:49.801861+00:00 app[web.1]: [2013-05-08 12:33:49] INFO  WEBrick
 1.3.1
2013-05-08T12:33:49.801861+00:00 app[web.1]: [2013-05-08 12:33:49] INFO  ruby 1.
9.2 (2011-07-09) [x86_64-linux]
2013-05-08T12:33:49.802294+00:00 app[web.1]: [2013-05-08 12:33:49] INFO  WEBrick
::HTTPServer#start: pid=2 port=23102
2013-05-08T12:33:50.375695+00:00 heroku[web.1]: State changed from starting to u
p
2013-05-08T12:33:51.484090+00:00 app[web.1]: Started GET "/" for 155.198.164.33
at 2013-05-08 12:33:51 +0000
2013-05-08T12:33:51.625244+00:00 app[web.1]: Processing by PostsController#index
 as HTML
2013-05-08T12:33:51.793939+00:00 app[web.1]:   Rendered posts/index.html.erb wit
hin layouts/application (8.0ms)
2013-05-08T12:33:51.879791+00:00 app[web.1]: Completed 500 Internal Server Error
 in 254ms
2013-05-08T12:33:51.881623+00:00 app[web.1]:
2013-05-08T12:33:51.885578+00:00 heroku[router]: at=info method=GET path=/ host=
warm-eyrie-3091.herokuapp.com fwd="155.198.164.33" dyno=web.1 connect=2ms servic
e=412ms status=500 bytes=643
2013-05-08T12:33:51.881623+00:00 app[web.1]:     156:
2013-05-08T12:33:51.881623+00:00 app[web.1]:     158: </body>
2013-05-08T12:33:51.881623+00:00 app[web.1]: ActionView::Template::Error (couldn
't find file 'foundation'
2013-05-08T12:33:51.881623+00:00 app[web.1]:   (in /app/app/assets/javascripts/a
pplication.js:15)):
2013-05-08T12:33:51.881623+00:00 app[web.1]:     154:
2013-05-08T12:33:51.881623+00:00 app[web.1]:     155:
2013-05-08T12:33:51.881906+00:00 app[web.1]:   app/controllers/posts_controller.
rb:7:in `index'
2013-05-08T12:33:51.881906+00:00 app[web.1]:
2013-05-08T12:33:51.881623+00:00 app[web.1]:     157: <%= javascript_include_tag
 "application" %>
2013-05-08T12:33:51.881623+00:00 app[web.1]:     159: </html>
2013-05-08T12:33:51.881623+00:00 app[web.1]:   app/views/layouts/application.htm
l.erb:157:in `_app_views_layouts_application_html_erb__3565313392971739647_35930
440'
2013-05-08T12:33:51.881906+00:00 app[web.1]:
2013-05-08T12:33:52.413616+00:00 heroku[router]: at=info method=GET path=/favico
n.ico host=warm-eyrie-3091.herokuapp.com fwd="155.198.164.33" dyno=web.1 connect
=1ms service=7ms status=304 bytes=0

您在heroku使用postgreSQL,因此您必須將config / database.yml文件更改為

production:
  adapter: PostgreSQL
  database: production
  pool: 5
  timeout: 5000

然后再次遷移

 1)heroku run rake db:reset 
 2) heroku run rake db:migrate 
 3)heroku restart 
 4)heroku open

在您的生產組中添加稀薄的寶石

group :production do
   gem 'thin'
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM