生产中的数据库创建问题

时间:2021-01-19 14:50:18

标签: ruby-on-rails nginx puma

我需要使用 nginx 和 puma 创建 rails 应用程序。我遵循了本指南:https://www.codeflow.site/fr/article/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04

但这条线没有按预期工作:

RAILS_ENV=production rake db:create

它会丢弃以下错误:

** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:create
no implicit conversion of nil into String
Couldn't create '' database. Please check your configuration.
rake aborted!
TypeError: no implicit conversion of nil into String
[...]
Tasks: TOP => db:create

这是我的database.yml文件的内容:

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 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:
     <<: *default
     host: localhost
     adapter: postgresql
     encoding: utf8
     database:
     pool: 5
     username: user
     password: mdp

2 个答案:

答案 0 :(得分:1)

你可以检查 config/database.yml 文件 production database 名称

一定是这样

production:
  <<: *default
  database: app_production

答案 1 :(得分:0)

所有环境必须使用相同的数据库适配器

PostgreSQL 的示例 database.yml 文件。你能检查一下这个配置吗

# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  pool: <%= ENV.fetch("DB_POOL_SIZE") { 15 } %>

development:
  <<: *default
  database: myapp_development


test:
  <<: *default
  database: myapp_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>
#
production:
  <<: *default
  username: user
  password: mdp
  database: myapp_production