我在Digital Ocean上有一个Rails 4.2应用程序。在部署注释模型(使用迁移文件)之后,它在开发中可以正常工作,但在生产中却不行。 我一直在使用Capistrano(根据本教程 - https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma)部署一直很顺利。
这是我的迁移文件(部署中缺少)。
class CreateComments < ActiveRecord::Migration
def change
create_table :comments do |t|
t.references :user, index: true, foreign_key: true
t.text :body
t.references :path, index: true, foreign_key: true
t.timestamps null: false
end
end
end
我检查过,可以在生产和开发匹配中看到我的架构,并参考迁移文件中的最后一个引用。 但是什么时候
当我使用rails console生产时,我可以看到注释表不存在。这是我的控制台中的消息。
Loading production environment (Rails 4.2.5)
2.2.1 :001 > Comment.all
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation "comments" does not exist
LINE 1: SELECT "comments".* FROM "comments"
^
: SELECT "comments".* FROM "comments"
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in exec_no_cache'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:472:in `block in log'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract_adapter.rb:466:in `log'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `exec_no_cache'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:584:in `execute_and_clear'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `exec_query'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:355:in `select'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/database_statements.rb:32:in `select_all'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/query_cache.rb:70:in `select_all'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/querying.rb:39:in `find_by_sql'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:639:in `exec_queries'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:515:in `load'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:243:in `to_a'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.5/lib/active_record/relation.rb:630:in `inspect'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:110:in `start'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/console.rb:9:in `start'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:45:in `require'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:45:in `block in exec_app_rails'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:34:in `loop'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/app_rails_loader.rb:34:in `exec_app_rails'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/cli.rb:5:in `<top (required)>'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/bin/rails:9:in `require'
from /home/laurie/apps/friendlyroad-rails/shared/bundle/ruby/2.2.0/gems/railties-4.2.5/bin/rails:9:in `<top (required)>'
from /home/laurie/.rvm/gems/ruby-2.2.1/bin/rails:23:in `load'
from /home/laurie/.rvm/gems/ruby-2.2.1/bin/rails:23:in `<main>'
from /home/laurie/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /home/laurie/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'2.2.1 :002 >
我也试过sudo-apt-get clean,我已经重置了我的数据库,添加了action-pack缓存gems并重启了我的服务器几次。
我的生产日志列出了没有渲染的评论视图文件(因为没有评论表)。
运行rake db:migrate:status显示&#34;没有文件&#34;
up 20151224215110 Devise create users
up 20151231173736 Add first name last name to users
up 20160112022120 Add role to users
up 20160122204744 Create paths
up 20160123004558 Add attachment image to paths
up 20160124191428 Remove user id from paths
up 20160124191601 Add user id to paths
up 20160124212622 Remove bio from users
up 20160124213023 Add bio to users
up 20160124213311 Remove title from paths
up 20160124213624 Add title content to paths
up 20160204222816 ********** NO FILE **********
检查目录(生产服务器)我看到文件不存在。
此外,删除了旧的迁移,检查了我的服务器的内存等。来了空白?
答案 0 :(得分:0)
我知道他是一个愚蠢的问题,但你是否在生产环境中使用控制台?
RAILS_ENV=production rails c