Models model (migrate introduction)--note

Source: Internet
Author: User

Before 1.6, Django only supported adding a new model to the database, and could not edit or modify the existing model. At the time, these Django-missing features could be implemented in south.

1. New commands

Django 1.7 brings us three new commands:

    • Migrate: Used to perform migration actions
    • Makemigrations: Create a new migration policy file based on the current model
    • Sqlmigrate: Displaying migrated SQL statements

It is important to note that migration is app-based, so we can not enable the migration feature for some apps.

2. How to use

The use of migrations is simple: Modify the model, such as adding field and then running

    python manager.  PY makemigrations     appname //appname can be added, not added. Write the appname, then update the current app; Otherwise, all Installed_app are updated. 

Your mmodel will be scanned and then compared to the previous version to generate this migration file in the app's migrations directory.

We recommend reviewing the migration file to make sure there are no problems. Then run:

    Python manager.  AppName //appname can be added, not added. Write the appname, then update the current app; Otherwise, all Installed_app are updated. 

The Migrate command compares and applies the migration.

Sqlmigrate generate SQL statements to migrate, available for database

Python manage.py sqlmigrate appname migration_no//eg:python manage.py sqlmigrate hi 0001

3. From south to the new Django migrations

If you want to upgrade from south to the latest Django migration, you can follow these steps:

    • Make sure the migration in South are all applied.
    • Remove South from Installed_apps
    • Delete all files in the migration directory under each app, except __init__.py
    • Run Python manager.py makemigrations, Django initializes migration
    • Running Python manager.py migrate, Django will discover that the database and the initialized migration are the same, marking them as applied

Original link: http://www.weiguda.com/blog/72/

Models model (migrate introduction)--note

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.