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

📅2025年5月10日
📝ブログ記事
【Rails】Renderにデータベースをデプロイした時のエラー解消

概要

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の設定をビルドスクリプトに追加した

#!/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

参考

https://qiita.com/Neptune/items/ed2d5355bffd989e5002

この記事はいかがでしたか?

他の記事もぜひご覧ください。技術的な学びや開発の記録を共有しています。