Django South : How To Fix The UnknownMigration Exception Error
I am fairly new to using django-south and bumped into an odd problem with creating and then applying migrations using django-south. All I wanted to do was to migrate the schema by adding a new field to a model. After creating the repository field in models.py, I went ahead and ran the following command:
./manage.py schemamigration app_name --add-field Model.field_name
Followed by:
./manage.py migrate app_name
This resulted in a message from South saying that there was nothing new to migrate. To get around this I specified the exact migration by doing this:
./manage.py migrate app_name migration_name
This resulted in the south.exceptions.UnknownMigration error. This made me think that the migration was not created in the app_name/migrations/ directory. So I went ahead and checked the folder, and the migration file was there. It was named 0003_add_field_Model.field_name.py. So far so good.
My next thought was to check the south_migrationhistory table and make sure everything was in order. It was. So I tried running the migrate command again and received the same UnknownMigration error.
I was stumped. Why wasn't South seeing my new migration?
Having some extra time I decided to look at the code from where the exceptions was being raised, which is in the south/migrations/base.py file. On line 72 I saw that South looks at migration files that do not have a dot in the file name. Since my migration file was called 0003_add_field_Model.field_name then South was not registering the migration.
The Fix
To fix the problem, I ran the following command:
./manage.py schemamigrate app_name "add_custom_field" --add_field Model.field_name
This created a new file in the app_name/migrations/ using the "add_custom_file" message meaning it the migration file name no longer had a period in it and South was able to register the migration.
It would probably be a good idea to make South automatically remove the period from the file name when adding a field.
Meta
Published: Sept. 11, 2011
Author: Emilian Felecan
Word Count: 301
Next: Configuring application settings for a Django project
Previous: Dynamic fields inside a form do not get posted
Tags
None