The causes and Solutions of errors in Django Database Migration
This article mainly explains the causes and solutions of errors in Django database migration, which interested friends may wish to have a look at. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the causes and solutions of errors in Django database migration.
Django performs database migration
Cause: because the migration file is inconsistent with the migration record in the database
Workaround python manage.py migrate app name-the fake migration file name marks the specified migration file as mapped, and the Sql statement for the migration file will not be executed.
If you don't know which migration file has the problem, you can delete all the migration files under the app, then delete all the migration files of the app in the migration file table django_migrations in the database, and then use python manage.py makemigrations app_name to generate a migration file after clearly mapping the fields and classes of the table. Then use python manage.py migrate-- fake-initial to save the migration file of the first table to the database.
Generate the model according to the database
Make python manage.py inspectdb > file path
Needs to be corrected.
The name may be too long, or it may be related to the key word.
The model needs to be put into the relevant app
Tables connected by foreign keys need to be adjusted
Execute marking command
At this point, I believe that everyone on the "Django database migration error causes and solutions" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!