简体   繁体   English

无法使用Rails 5连接到Heroku上的安装数据库

[英]Cannot connect to setup database on heroku with rails 5

Not sure what I am doing wrong, I tried just leaving out the production section in my database.yml but that didn't work, now I have this: 不知道我在做什么错,我尝试只在我的database.yml中忽略生产部分,但这没有用,现在我有了:

development:
  ...

test:
  ...

production:
  database: myapp_production
  pool: 5

My gemfile: 我的gemfile:

gem 'pg', :group => :production
gem 'mysql2', '>= 0.3.18', '< 0.5', :group => [:development, :test]

I am getting this error when running: 运行时出现此错误:

Running rake db:setup on ⬢ still-crag-69600... up, run.8579 (Free)
rake aborted!
ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: ["development", "test"]
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:246:in `resolve_symbol_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:227:in `resolve_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:141:in `resolve'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_handling.rb:55:in `establish_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:139:in `create_current'

You need to add this under production: 您需要在生产中添加此代码:

  adapter: postgresql
  url: <%= ENV['DATABASE_URL'] %>

Ensure that you have created a postgresql addon . 确保已创建一个postgresql插件 DATABASE_URL environment variable is set automatically when you add a heroku postgresql addon. 添加heroku postgresql插件时,会自动设置DATABASE_URL环境变量。

Try below code in database.yml: 尝试下面的database.yml代码:

development:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: db_name
  pool: 5
  username: root
  password: root

production:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: db_name
  pool: 5
  username: root
  password: root

test:
  adapter: postgresql
  encoding: utf8
  reconnect: false
  database: db_name
  pool: 5
  username: root
  password: root

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM