Migrating a Django app using South

Hi all,

I am back with some things I have learned using South.

Here it goes:

There are many times where we want to use South on existing apps. In the previous post, I’ve only pointed to the exsiting tutorials found on South’s website at http://south.aeracode.org/docs/convertinganapp.html.

In case you want to know what the whole process looks like, here it is:

Firstly, assuming you have an existing project, for instance se. And within se you have an existing app called ajax. Here’s the original models.py:

Go to settings.py, and add  ‘south’ in your installed apps section.
Next, you will be required to run the following command in your terminal:

You should see something like this:
Syncing…
Creating table south_migrationhistory
No fixtures found.
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.admin
> se.example
> se.register
> se.ajax
> south
Not synced (use migrations):
-
(use ./manage.py migrate to migrate these)
Syncing…Creating table south_migrationhistoryNo fixtures found.
Synced: > django.contrib.auth > django.contrib.contenttypes > django.contrib.sessions > django.contrib.sites > django.contrib.admin > se.example > se.register > se.ajax > south
Not synced (use migrations): – (use ./manage.py migrate to migrate these)

After you received the above response, you will need to run the next command:

You will see a response where South is creating migrations directory and so on.
The response above is based on the assumption that your models defined in models.py is in sync as per what is found in you database.
Now, let us make a small change in your models.py: Change the original models.py as shown earlier in the post, by appending the following line to it:

And now for the final step, run the following command in your terminal:

You will see a response from South stating that “The field ‘Ajax.text’ does not have a default specified, yet is NOT NULL”. This simply means that you need to specify some kind of default values for the existing fields that originally do not have the field text. In my case, I typed in “this is default“.

Now once you are done, you might want to pop over to your database, which is phpmyadmin in my case, and you will see that the new  field is now added to the Ajax model.

That’s it!

Ok that’s all for now.

See ya.