"找不到表"运行db:setup之后

时间:2015-07-21 10:57:48

标签: ruby-on-rails ruby ruby-on-rails-4 activerecord

在本地开发机器中,

  1. 我添加了一个rails g model Place title:string location:string

  2. 的模型
  3. seeds.rb

  4. 中添加了一些默认数据
  5. rake db:setup
  6. 该功能正常运行,因此在具有运行rails应用程序的服务器中,

    1. git pull编辑了来源,但没有停止正在运行的应用程序
    2. rake db:setup
    3. 在数据库控制台中检查时创建了表和数据。
    4. 向应用发出请求但发生错误:ActiveRecord::StatementInvalid "Could not find table(place)
    5. rake db:migrate,然后一切顺利。
    6. 在步骤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
      

0 个答案:

没有答案