【问题标题】:Problems with heroku rake db:resetheroku rake db:reset 的问题
【发布时间】:2016-04-14 15:43:36
【问题描述】:

我有一个问题,我将我的应用程序推送到 github 并使用 heroku 进行了部署,一切正常,但是当我运行 heroku run --app myapp rake db:reset(在 heroku 上填充数据库)时,我发现以下消息充满了错误(我只显示我认为重要的部分,因为消息太长)

FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
.
.
.
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Couldn't drop d5q6ajst4p4d97
FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
.
.
.
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "database"=> [DATABASE], "pool"=>5, "username"=> [USERNAME], "password"=> [PASSWORD], "port"=>5432, "host"=> [HOST]}
-- enable_extension("plpgsql")
   -> 0.0370s
-- create_table("heros", {:force=>:cascade})
   -> 0.0307s
-- initialize_schema_migrations_table()
   -> 0.0579s

注意:我隐藏了用户名、密码等...

在部署的应用程序中一切正常,但是在 heroku 中创建rake db: reset 时看到这么多错误,我觉得很难看,所以在看到这个之后,我搜索了如何解决这个问题,并找到了一些宣扬相同解决方案的帖子,所以我按照建议运行命令heroku pg:reset DATABASE_URL --app myapp,它成功结束,但是当我再次尝试运行rake db:reset时出现相同的错误消息,会发生什么?

这是我的 database.yml

development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username:
  password:

production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username:
  password:

【问题讨论】:

    标签: ruby-on-rails postgresql heroku rails-postgresql


    【解决方案1】:

    Heroku,作为一个 共享 服务不允许用户访问 dropcreate 数据库 - 因此运行 rake db:reset 时出现错误

    因此heroku pg:reset 是作为执行数据库重置的命令出现的。

    https://devcenter.heroku.com/articles/rake

    【讨论】:

      【解决方案2】:

      我遇到了同样的错误,我已经修复了它

      heroku pg:reset DATABASE_URL
      heroku rake db:migrate
      

      根据你的错误

      还有你的database.yml指向postgres用户来连接heroku中的数据库

      它不应该是 postgres 作为生产模式的用户。

      所以

      Active Record 4.1+ 安全阀

      如果您需要连接到不同的数据库而不是 ENV['DATABASE_URL'] Rails 4.1+ 支持 database.yml 中的 URL 键 优先的文件。

      production:
        url: <%= ENV["SOME_OTHER_URL"] %>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-05
        • 2015-06-15
        • 2011-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-13
        • 2012-05-05
        相关资源
        最近更新 更多