Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Operation commands related to database migration in Django

Shulou Source: shulou.com Published: 2022-06-02 05:16:00 10月13日 Update

This article introduces the relevant knowledge of "operation commands related to database migration in Django". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Python manage.py makemigrations

This command creates a database migration script to generate a migration script for model that has been modified by app

Python manage.py migrate

This command is that the database executes the migration script to synchronize to the database, and this command operates with caution.

If you want to be accurate to a certain migration file (0004_xxx.py):

Python manage.py migrate app_name 004

If you want to see the execution status of the migration file, you can view it with the showmigrations command:

$python manage.py showmigrations

Displays the migrations and status known to django.

Error

The command of the database may fall if you are not careful. In particular, the migrate command, because the django database contains records of migrations, if the migrations file is missing, it is likely to cause migrate failure. Therefore, it is necessary to add migrations files to version control to ensure that migrations records and files match at the time of development.

If the migrate fails, it is probably because the change information contained in the migration file cannot be completed due to the constraints of the current database. At this point, you should go to the data to find the location of these records or keys, delete and redo. Generally speaking, the tables in which these data exist are: tables corresponding to foreign key constraints, auth_permission, django_content_type and django_migrations.

This is the end of the content of "operational commands related to database migration in Django". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Data commands databases files scripts content more status knowledge practical accurate necessary learned and then slightly careless location information dilemma actual situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Docker MariaDB Shulou Information