Reputation: 31181
Due to merging several feature branches into my project, I have the following migrations:
0001_initial.py
0002_auto__add_field_userprofile_telephone__add_field_userprofile_timezone.py
0003_auto.py
0004_auto__del_field_organisation_admin.py
0005_auto__add_field_organisation_permitted_domains.py
0005_auto__add_field_userprofile_currency.py
Note that I have two duplicate 0005 migrations. These ran fine, and deployed fine on my production system.
$ python manage.py migrate accounts --list [17:11:42]
accounts
(*) 0001_initial
(*) 0002_auto__add_field_userprofile_telephone__add_field_userprofile_timezone
(*) 0003_auto
(*) 0004_auto__del_field_organisation_admin
(*) 0005_auto__add_field_organisation_permitted_domains
(*) 0005_auto__add_field_userprofile_currency
My table has the correct columns:
$ psql
db_my_project=# \d+ accounts_organisation
db_my_project=# \d+ accounts_userprofile
... shows currency and permitted_domain, suggesting the migrations worked correctly
However, if I try to create a new migration, South thinks that I haven't added the column' permitted_domains' to my model:
$ python manage.py schemamigration accounts --auto [17:16:15]
+ Added field permitted_domains on accounts.Organisation
Created 0006_auto__add_field_organisation_permitted_domains.py. You can now apply this migration with: ./manage.py migrate accounts
How do I fix this?
Upvotes: 3
Views: 2317
Reputation: 29804
It is a very specific problem, I hope this helps, do the following:
1) Rename this file: 0005_auto__add_field_organisation_permitted_domains
to 0006_auto__add_field_organisation_permitted_domains
2) Rename the number of your recently migration file from 0006 to 0007
3) Issue the command python manage.py migrate account 0006 --fake
to deceive south.
4) Issue the command python manage.py migrate account 0007
That might get the south engine in sycn again with your application
Hope this helps!
Upvotes: 2
Reputation: 46
From the docs: http://south.readthedocs.org/en/0.7.6/autodetector.html
When the autodetector runs, it compares your current models with those frozen in your most recent migration on the app, and if it finds any changes, yields one or more Actions to the South migration-file-writer.
The migrations keep a frozen version of the fields within the model in a dict.
Therefore:
In 0005_auto__add_field_organisation_permitted_domains
the Organisation class will have a field permitted_domains
but in 0005_auto__add_field_userprofile_currency
it will not. When you run:
$ python manage.py schemamigrate accounts --auto
this will compare the current state of the code against the record of the fields store in 0005_auto_add_field_userprofile_currency
, thus leading south to add the field for a second time.
If you copy the line for the 'permitted_domains' field from 0005_auto__add_field_organisation_permitted_domains
to 0005_auto__add_field_userprofile_currency
this will solve your problem.
Upvotes: 3