【问题标题】:Database creation issue on production生产中的数据库创建问题
【发布时间】:2021-01-19 14:50:18
【问题描述】:

我需要使用 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

【问题讨论】:

  • 是您的 database.yml 文件,还是问题中的缩进关闭?
  • 是的,这是我的 database.yml
  • 好吧,那缩进全错了,你必须修复它。

标签: ruby-on-rails nginx puma


【解决方案1】:

你能检查一下config/database.yml文件productiondatabase名字

一定是这样的

production:
  <<: *default
  database: app_production

【讨论】:

    【解决方案2】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2011-04-11
      • 2014-10-26
      • 2018-03-16
      • 2017-01-27
      • 2019-12-25
      • 1970-01-01
      • 2011-10-17
      • 2013-12-17
      • 1970-01-01
      相关资源
      最近更新 更多