【问题标题】:heroku gives error ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: ["development", "test"]heroku 给出错误 ActiveRecord::AdapterNotSpecified: 'production' 数据库未配置。可用:[“开发”,“测试”]
【发布时间】:2018-12-03 00:01:28
【问题描述】:

我的数据库.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: organic_tomatoes_development
  pool: 5
  username: root
  password: password

test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: organic_tomatoes_test
  pool: 5
  username: root
  password: password

我在 heroku 上部署我的网站。 当我运行heroku run rake db:migrate 它给出了一个错误

ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: ["development", "test"]

我该如何解决这个错误?

【问题讨论】:

标签: mysql ruby-on-rails ruby heroku heroku-cli


【解决方案1】:

根据分享的描述,您只指定了开发和测试环境,您还需要添加生产环境设置

但除此之外,您需要将 ClearDB 添加为附加组件才能使用 mysql db。

单击显示配置变量并复制 CLEARDB_DATABASE_URL 值。

mysql://xxxxx@xxxx.cleardb.net/xxxxx?reconnect=true。

@ 符号之后直到 / 的所有内容都是 DB_HOST

之后/之前的所有内容?是 DB_DATABASE

// until : 之后的字符串是 DB_USERNAME

: 和 @ 之间的字符串是 DB_PASSWORD

   development:
     adapter: mysql2
     encoding: utf8
     reconnect: false
     database: organic_tomatoes_development
     pool: 5
     username: root
     password: password

   test:
    adapter: mysql2
    encoding: utf8
    reconnect: false
    database: organic_tomatoes_test
    pool: 5
    username: root
    password: password

   production:
     adapter: mysql2
     encoding: utf8
     username: xxxx
     password: xxxx
    database: ENV["CLEARDB_DATABASE_URL"]
    pool: 5

【讨论】:

    【解决方案2】:

    在你的 database.yml 中创建一个生产条目

    production::
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: organic_tomatoes_production
      pool: 5
      username: root
      password: password
    

    【讨论】:

      【解决方案3】:
      production:
          adapter: mysql2
          encoding: utf8
          reconnect: false
          database: organic_tomatoes_production
          pool: 5
      

      你可以试试这个吗?

      【讨论】:

        【解决方案4】:

        我今天早上遇到了这个问题,解决方法是在运行命令之前设置RAILS_ENV变量'

        RAILS_ENV=development heroku local
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-08-19
          • 2017-03-27
          • 1970-01-01
          • 2014-06-13
          • 1970-01-01
          • 2016-07-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多