Django migrations : relation already exists

前端 未结 6 942
南笙
南笙 2021-02-06 18:46

I have trouble with django model migrations. I have some models in my app, and I already have some data inside. When I added some models in my application, and I run mak

6条回答
  •  被撕碎了的回忆
    2021-02-06 19:22

    How about doing this way ?

    python manage.py makemigrations

    (Skip this step if you have already have migration file ready)

    It will create migrations for that package lets say with a name like 0001_initial.py

    Edit the file manually so that you delete all models there except that was already created in database.

    Now you do a fake migration. This will sync your database with models.

    python manage.py migrate --fake

    Then run makemigrations again to have rest of the tables created along with a new migration file.

    python manage.py makemigrations

    Regarding your other question, Why makemigrations didn't recogonize your models can be because of reasons like:

    1. Migrations for those changes are already there in some migration file.
    2. You missed it to mention package_name in INSTALLED_APPS but i believe you did it here.

提交回复
热议问题