rails 乘客部署 - 找不到 table 'users'

rails passenger deployment - Could not find table 'users'

passengers's offical tutorial 没有出错。我从 git 中提取代码并使用此命令

bundle install --deployment --without development test
bundle exec rake assets:precompile db:migrate

我的database.yml

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  adapter: sqlite3
  database: db/production.sqlite3

log/production.log:

I, [2015-08-28T15:54:47.310372 #32086]  INFO -- : Started GET "/" for 176.219.167.108 at 2015-08-28 15:54:47 -0400
I, [2015-08-28T15:54:47.334003 #32086]  INFO -- : Processing by ArticlesController#index as HTML
I, [2015-08-28T15:54:47.365923 #32086]  INFO -- : Completed 500 Internal Server Error in 31ms (ActiveRecord: 0.9ms)
F, [2015-08-28T15:54:47.367834 #32086] FATAL -- :
ActiveRecord::StatementInvalid (Could not find table 'users'):
  app/models/ability.rb:5:in `initialize'

我在 rails 控制台

上使用此命令检查了我有用户 table
ActiveRecord::Base.connection.tables

顺便说一句,我为用户设计 gem。 我是 rails 的绝对初学者,希望我写的信息足以让您理解问题。

我的服务器信息:Digital Ocean 5$ droplet。 Ubuntu 14.04。 Nginx,乘客,rvm,ruby 2.2.2.

和我的 500 页:image

您应该能够通过简单地 运行 执行以下操作来解决此问题:

RAILS_ENV=production bundle exec rake db:migrate

但是,我不建议您在生产中使用 SQLite,因为这种类型的数据库最适合用于测试和开发目的。您可能想研究使用 PostgreSQL。以下应该适合您:

在您的 Gemfile 中,添加:

gem 'pg', :group => :production

运行bundle install。 然后在database.yml中使用:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 10
  timeout: 5000

login: &login
  username: <%= ENV['DATABASE_USER'] %>
  password: <%= ENV['DATABASE_PASS'] %>

production:
  <<: *default
  <<: *login
  database: your_database_name

出于安全原因,最好不要在 Rails 应用程序的文件中以明文形式写入数据库用户名和密码。最好将它们设置为环境变量。为此,请编辑 Droplet 上的 ~/.bash_profile 文件并添加以下内容:

export DATABASE_USER=your_username
export DATABASE_PASS=your_password

退出该文件并从命令行 运行 source ~/.bash_profile 将这些新设置加载到内存中。

然后您需要创建 PostgreSQL 数据库,其中有 plenty of guides online

完成后,您将需要 运行 在生产中 运行 迁移迁移时对 SQLite 使用相同的命令:

RAILS_ENV=production bundle exec rake db:migrate

希望对您有所帮助!