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?

Django migrate時のエラー django.db.migrations.exceptions.InconsistentMigrationHistory

Posted at

エラー発生

開発環境で初回に以下のコマンドを実行した

python3 manage.py makemigrations
python3 manage.py migrate

すると以下のようにエラーが出た

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration admin.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.

原因

マイグレーションの順番がDBの履歴と食い違っているのが原因です。
migrationsフォルダを消したり再作成するとよく出るやつです。

原因の解消

以下のコマンドを実行して解消した
このコマンドはデータベースの内容を初期化するので、データは全て削除されます。

rm db.sqlite3
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
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?