代码之家  ›  专栏  ›  技术社区  ›  Blankman

无法使用rails 5连接到heroku上的安装数据库

  •  0
  • Blankman  · 技术社区  · 7 年前

    我不确定自己做错了什么,我试着在数据库中省略了生产部分。yml但这不起作用,现在我有了这个:

    development:
      ...
    
    test:
      ...
    
    production:
      database: myapp_production
      pool: 5
    

    我的GEM文件:

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

    运行时出现以下错误:

    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'
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   mingca    7 年前

    您需要在生产中添加以下内容:

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

    确保您已经创建了 postgresql addon . DATABASE_URL 添加heroku postgresql插件时,会自动设置环境变量。

        2
  •  0
  •   puneet18    7 年前

    在数据库中尝试以下代码。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