2015年6月15日月曜日

herokuでrake db:migrate:resetするとエラーになる

herokuでdbのmigrateを再実行したかったので、
db:migrate:resetを実行したらエラーになったときの対応です。

実行してみたときのエラーはこんな感じ
$ heroku run rake db:migrate:reset
Running `rake db:migrate:reset` attached to terminal... up, run.7795
FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `retrieve_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:87:in `connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:30:in `drop'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:114:in `drop'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:128:in `block in drop_current'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:274:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:127:in `drop_current'
/app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:28:in `block (2 levels) in '
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/app/bin/rake:8:in `
' Couldn't drop db_table FATAL: permission denied for database "postgres" DETAIL: User does not have CONNECT privilege. /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `retrieve_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:113:in `retrieve_connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/connection_handling.rb:87:in `connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:93:in `create' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:274:in `each' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/tasks/database_tasks.rb:106:in `create_current' /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.1/lib/active_record/railties/databases.rake:17:in `block (2 levels) in ' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in `call' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in `each' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in `execute' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:199:in `each' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:165:in `invoke' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `each' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:100:in `top_level' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:78:in `block in run' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling' /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run' /app/bin/rake:8:in `
' Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "pool"=>5, "database"=>"db_table", "username"=>"user", "password"=>"password", "port"=>5432, "host"=>"hostname"}
調べてみたところ、DBを書き換えるようなコマンドはpermissionエラーになるようになっているようです。
rakeタスクでやらずにpostgresqlを直接操作して削除し、
それからrake db:migrateでやるとよいようです。
$ heroku pg:reset DATABASE
 
 !    WARNING: Destructive Action
 !    This command will affect the app: heroku-host
 !    To proceed, type "heroku-host" or re-run this command with --confirm heroku-host
 
> heroku-host
Resetting DATABASE_URL... done

$ heroku run rake db:migrate


参考URL
http://blog.aripei.com/2013/10/rails-operation-in-heoku.html

0 件のコメント:

コメントを投稿