Django2.0 added a field to the existing model to report an error.

Django2.0 adds fields to the existing model

then execute Python manage.py makemigrations appname
but execute Python manage.py migrate prompt table already exists

how to add fields to an existing model

Oct.12,2021

add parameters in the second step, run the following command:

 python manage.py migrate --fake-initial

document is as follows :

Adding migrations to new apps is straightforward - they come preconfigured to accept migrations, and so just run makemigrations once you' ve made some changes.

If your app already has models and database tables, and doesn' t have migrations yet (for example, you created it against a previous Django version), you' ll need to convert it to use migrations; this is a simple process:

$ python manage.py makemigrations your_app_label
This will make a new initial migration for your app. Now, run python manage.py migrate --fake-initial, and Django will detect that you have an initial migration and that the tables it wants to create already exist, and will mark the migration as already applied. (Without the migrate --fake-initial flag, the command would error out because the tables it wants to create already exist.)

you deleted the migration file. Please take good care of the migration documents.

Menu