Django Learning--Database synchronization Tips

Source: Internet
Author: User

Synchronize database: Use the two commands above to synchronize the database 1. Know Migrations directory: Migrations directory function: used to store the database script generated by the Makemigrations command, the generated script in the inside is not easily modified. to use the database synchronization function properly, the app directory must have the Migrations directory, and the directory exists under the __init__.py file.
2. Recognize the fields in a data table (django_migrations) Table: App:app Name: The name of the script file executed applied: The time the script was executed also shows the name of the app that Hello_app is running, and the script file executed is 0001_ initial.py, time also shows.
3. Some database related commands: (manage.py to run) Flush: Clear the database, restore the database to the original state makemigrations [appname]: Generate database synchronization script, you can specify the specific synchronization that appmigrate [ AppName]: Synchronize Database (*) showmigrations [app_lable]: View generated Database synchronization script (*)
Sqlflush <appname>: View generate Empty Database script (*) must have the name of the app sqlmigrate: View SQL statements for database synchronization (*)
Note: In the development process, after the database synchronization error operation, it is unavoidable to encounter the situation that can not be synchronized successfully, to solve the problem, one is to analyze the generated database script and Django_migrations synchronization records in the match. Another simple and rough way is to put the script in the Migrations directory (out of the __init_.py, where not to delete, and then delete the database, then create a new database, the database synchronization operation is done once.



From for notes (Wiz)

Django Learning--Database synchronization Tips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.