LoginSignup
3
3

More than 5 years have passed since last update.

herokuのDB本番環境リセット(PostgreSQL)

Last updated at Posted at 2019-03-18

下記のページなどを参考に、herokuの本番環境DB(PostgreSQL)のリセットを行ったが、
なかなか思う様にできなかったので、備忘録。

環境としては、
・IDE:cloud 9
・サーバー:heroku
・本番DB:PostgreSQL

1. heroku pg:reset DATABASE_URLを実行した後、heroku run rails db:migrateを実行。

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "〇〇〇" does not exist

のエラーが発生してしまう。

2. heroku run rails db:schema:load RAILS_ENV=productionを実行。

 rails aborted!
ActiveRecord::NoEnvironmentInSchemaError: 

Environment data not found in the schema. To resolve this issue, run: 

        bin/rails db:environment:set RAILS_ENV=production

との警告が表示される。

3. 警告を基に、heroku run rails db:environment:set RAILS_ENV=production db:schema:loadを実行。

2の警告を基に、RAILS_ENV=productionを変えて、db:environment:set RAILS_ENV=productionを追記。

ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database.
If you are sure you want to continue, run the same command with the environment variable:
DISABLE_DATABASE_ENVIRONMENT_CHECK=1

との警告が表示される。

4. 警告を基に、heroku run rails db:environment:set DISABLE_DATABASE_ENVIRONMENT_CHECK=1 RAILS_ENV=production db:schema:loadを実行。

3の警告を基に、DISABLE_DATABASE_ENVIRONMENT_CHECK=1を追記。
DBのリセットに成功!!
その後、heroku run rails db:migrateを実行し、無事本番環境のDBを再構築することができた。

まとめ

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3