0
1

【Rails】Renderにデータベースをデプロイした時のエラー解消

Posted at

概要

Railsチュートリアルの第10章を進めていた時、
データベースのマイグレーションの設定をRenderにデプロイしたときにビルドエラーが発生しました。

rails aborted!
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

Tasks: TOP => db:migrate:reset => db:drop => db:check_protected_environments
(See full trace by running task with --trace)
==> Build failed 😞

結論(解決策)

DISABLE_DATABASE_ENVIRONMENT_CHECK=1の設定をビルドスクリプトに追加した

render-build.sh
#!/usr/bin/env bash
# exit on error
set -o errexit
bundle install
bundle exec rails assets:precompile
bundle exec rails assets:clean
bundle exec rails db:migrate
DISABLE_DATABASE_ENVIRONMENT_CHECK=1 bundle exec rails db:migrate:reset
bundle exec rails db:seed

参考

0
1
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
0
1