heroku给出错误activerecord::adapternotspecified:“production”数据库未配置可用:[“开发”,“测试”]

wqnecbli  于 2021-06-21  发布在  Mysql
关注(0)|答案(4)|浏览(281)

我的数据库.yml

  1. development:
  2. adapter: mysql2
  3. encoding: utf8
  4. reconnect: false
  5. database: organic_tomatoes_development
  6. pool: 5
  7. username: root
  8. password: password
  9. test:
  10. adapter: mysql2
  11. encoding: utf8
  12. reconnect: false
  13. database: organic_tomatoes_test
  14. pool: 5
  15. username: root
  16. password: password

我在heroku上部署了我的站点。当我跑的时候 heroku run rake db:migrate 它给出了一个错误

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

如何解决此错误?

icnyk63a

icnyk63a1#

  1. production:
  2. adapter: mysql2
  3. encoding: utf8
  4. reconnect: false
  5. database: organic_tomatoes_production
  6. pool: 5

你能试试这个吗?

91zkwejq

91zkwejq2#

在database.yml中创建生产条目

  1. production::
  2. adapter: mysql2
  3. encoding: utf8
  4. reconnect: false
  5. database: organic_tomatoes_production
  6. pool: 5
  7. username: root
  8. password: password
oxf4rvwz

oxf4rvwz3#

根据共享的描述,您只指定了开发和测试环境,还需要添加生产环境设置
但除此之外,您还需要添加cleardb作为使用mysql db的附加组件。
单击显示配置变量并复制cleardb\u数据库\u url值。
mysql://xx@x.cleardb.net/xx?reconnect=true.
在@符号之后的所有内容,直到/是db\u主机
之后/之前的一切?是数据库
//until:后面的字符串是db\u用户名
和@之间的字符串是db\u密码

  1. development:
  2. adapter: mysql2
  3. encoding: utf8
  4. reconnect: false
  5. database: organic_tomatoes_development
  6. pool: 5
  7. username: root
  8. password: password
  9. test:
  10. adapter: mysql2
  11. encoding: utf8
  12. reconnect: false
  13. database: organic_tomatoes_test
  14. pool: 5
  15. username: root
  16. password: password
  17. production:
  18. adapter: mysql2
  19. encoding: utf8
  20. username: xxxx
  21. password: xxxx
  22. database: ENV["CLEARDB_DATABASE_URL"]
  23. pool: 5
展开查看全部
cnjp1d6j

cnjp1d6j4#

我今天早上遇到了这个问题,解决办法是 RAILS_ENV 运行命令前的变量'

  1. RAILS_ENV=development heroku local

相关问题