Over the developing period of Django web application the models change a lot. Managing these changes in a team environment working on a Django project can become complicated. Unfortunately Django doesn’t capture the changes in the existing models. Until Django will provide an solution to this problem, you will need to use a schema migration tool. After I have browsed for such tools, I decided to use South. This post will explain how to use South.
Install South and verify that ‘south’ entry is added to INSTALLED_APPS in settings.py file. Run manage.py syncdb to create the South migration history table for the first time.
D:\NetBeansProjects\ProjectX\src\project>python manage.py syncdb
Creating table south_migrationhistory
Not synced (use migrations):
(use ./manage.py migrate to migrate these)
Create an initial migration for the application. Application means an entry from INSTALLED_APPS of settings.py file(for example: project.customer). This yields a migration that matches the existing database schema.
D:\NetBeansProjects\ProjectX\src\project>python manage.py schemamigration project.customer --initial
Creating migrations directory at 'D:\NetBeansProjects\ProjectX\src\project\..\project\cust
Creating __init__.py in 'D:\NetBeansProjects\ProjectX\src\project\..\project\customer\migr
+ Added model customer.Booking
+ Added unique constraint for ['booking_date', 'booking_number'] on customer.Bo
+ Added model customer.Address
Created 0001_initial.py. You can now apply this migration with: ./manage.py migr
The next step is to bring the application under South’s control.
D:\NetBeansProjects\ProjectX\src\project>python manage.py migrate project.customer 0001 --fake
- Soft matched migration 0001 to 0001_initial.
Running migrations for customer:
- Migrating forwards to 0001_initial.
The previous steps were necessary only once for setting South for the first time. Then after every change to the models the command schemamigration is used to generate a migration for the new models and fields. This example will add a new field test to the Booking model.
D:\NetBeansProjects\ProjectX\src\project>python manage.py schemamigration project.customer
? The field 'Booking.test_field' does not have a default specified, yet is NOT
? Since you are adding or removing this field, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now, and add a default to the field in models.py
? 2. Specify a one-off value to use for existing columns now
? Please select a choice: 2
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
+ Added field test_field on customer.Booking
Created 0002_auto__add_field_booking_test_field.py. You can now apply this migra
tion with: ./manage.py migrate project.customer
Now, apply the migration:
D:\NetBeansProjects\ProjectX\src\project>python manage.py migrate project.customer
Running migrations for customer:
- Migrating forwards to 0002_auto__add_field_booking_test_field.
- Loading initial data for customer.
Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.