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:
class Ajax(models.Model): title = models.CharField(max_length=200)
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:
python manage.py syncdb
You should see something like this:
Creating table south_migrationhistory
No fixtures found.
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:
python manage.py convert_to_south ajax
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:
text = models.CharField(max_length=200)
And now for the final step, run the following command in your terminal:
python manage.py migrate ajax
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.
Ok that’s all for now.