Use of new Django 1.7 data migration tool (migrations) and how to upgrade and convert from south

Source: Internet
Author: User

Before January 1.6, Django only supported adding new models to the database, but could not edit or modify existing models. At that time, the missing functions of Django could be implemented through south.

According to the official documentation, PostgreSQL databases are the best supported, followed by MySQL. Currently, SQLite cannot implement the complete migration function.

1. New commands

Django 1.7 brings us three new commands:

  • Migrate: used to execute migration actions

  • Makemigrations: Creates a new migration policy file based on the current model.

  • Sqlmigrate: displays the migrated SQL statement

It is worth noting that the migration is based on the app. Therefore, we can disable the migration function for some apps.

2. How to Use

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

    python manager.py makemigrations

Your Mmodel will be scanned and compared with the previous version. The migration file will be generated in the migrations directory of the app.

We recommend that you check the migration file to make sure there is no problem. Then run:

    python manager.py migrate

The migrate command will compare and apply the migration.

3. From south to new Django migrations

To upgrade from south to the latest Django migration, follow these steps:

  • Make sure all migration in south is applied.

  • Remove south from installed_apps

  • Delete all files in the migration directory of each app except _ init _. py

  • Run Python manager. py makemigrations. Django will initialize migration

  • Run Python manager. py migrate. Django will find that the database is the same as the initialized migration, and mark them as applied


Use of new Django 1.7 data migration tool (migrations) and how to upgrade and convert from south

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.