0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Rails] rails db:migrateが失敗したら、スキーマファイルからデータベースを構築しよう

0
Last updated at Posted at 2024-06-15

概要

マイグレーションに不整合がある場合、rails db:migrate が失敗することがあります。
過去のmigrationファイルから原因を特定し、修正しようとするとかなり時間がかかります。

このような時は rails db:schema:load コマンドを使うことで、スキーマファイルから迅速にデータベースを構築することができます。

マイグレーションコマンド

rails db:migrate:
db/migrate のマイグレーションファイルを順次実行する

rails db:schema:load:
db/schema.rbのスキーマ情報をそのままデータベースに反映する ※db/migrate のマイグレーションファイルは使わない

まとめ

既存プロジェクトの環境構築などで、マイグレーションが失敗した時のために頭の片隅に置いておくと役立つ時が来るかもしれません...

新規メンバー参画予定のため備忘録として執筆... :pencil:

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?