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