在本地开发机器中,
我添加了一个rails g model Place title:string location:string
在seeds.rb
rake db:setup
该功能正常运行,因此在具有运行rails应用程序的服务器中,
git pull
编辑了来源,但没有停止正在运行的应用程序rake db:setup
ActiveRecord::StatementInvalid "Could not find table(place)
rake db:migrate
,然后一切顺利。 在步骤4中可能导致ActiveRecord::StatementInvalid
错误的原因是什么?运行db:migrate
后,是否始终需要运行db:setup
Rails版本:4.2.3本地和服务器。
正在运行rake db:migrate:status
会显示以下输出。
Status Migration ID Migration Name
--------------------------------------------------
up 000 ********** NO FILE **********
up 20150721031229 Create places
数据库控制台显示以下输出。
sqlite> select * from schema_migrations;
0
20150721031229
编辑:在步骤4中添加了完整的错误回溯
Completed 500 Internal Server Error in 28ms (ActiveRecord: 13.2ms)
ActiveRecord::StatementInvalid (Could not find table 'places'):
app/models/place.rb:47:in `get_random_place'
app/models/place.rb:29:in `handle'
app/controllers/message_controller.rb:27:in `handle'
Rendered /home/deploy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.0ms)
Rendered /home/deploy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.8ms)
Rendered /home/deploy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms)
Rendered /home/deploy/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (16.6ms)
应用程序/模型/ place.rb:47
def self.get_random_place
offset = rand(Place.count)
place = Place.offset(offset).first
place
end