1
0

More than 3 years have passed since last update.

Djangoでアプリケーション名を変えたらmigrateができなくなってしまったときの対処方法をメモ

Last updated at Posted at 2021-03-08

環境

Python 3.8.7
Django==2.2

エラー内容

アカウントの編集とかの操作するアプリケーション名を変更して

python manage.py makemigrations

をしたら

Traceback (most recent call last):
略
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration socialaccount.0001_initial is applied before its dependency account_manage.0001_initial on database 'default'.

とエラーが発生。

python manage.py migrate

も同じエラー。
そこで、エラー文をググってみると、

があった!
書いてあるように、

python manage.py showmigraions

をやったら、前に作ったアプリケーションでmigrateしたデータが残ってた、、、。そりゃそうだな。

解決方法

すべてのアプリケーションのmigrations直下のinit.py以外のファイルを削除。

python manage.py makemigrations
python manage.py migrate

をしたら動いた!

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