Remove a model managed by south.

25 views
Skip to first unread message

Victor Liu

unread,
Oct 16, 2014, 2:58:40 AM10/16/14
to south...@googlegroups.com
Hi All

I currently have a problem about south migrations. Below is the background.

In reports app, there are two related tables. Report, and ReportConfig, also other models, but have less relation to  this problem. 

From the beginning, we add data migrations to Report and ReportConfig tables. There are also some migrations which updating ReportConfig.

Now I want to remove report_config table, as well as ReportConfig model, replacing it by a constant. ( there is no model ReportConfig anymore)

Steps I took.
1. remove ReportConfig from code.
2. run manage.py schemamigration reports
3. run manage.py migrate reports, then I came to this error.
UnknownMigration: Migration 'reports:0002_add_reports' probably doesn't exist.
ImportError: cannot import name ReportConfig from the first data migration of ReportConfig.

How to deal with this error? or remove ReportConfig safely? 

Any help will be appreciated.

Thanks
Best Regards

Victor Liu



Shai Berger

unread,
Oct 16, 2014, 6:31:43 AM10/16/14
to south...@googlegroups.com
Hi Victor,

The error indicates that you've made the mistake of importing the model from
the app into your data migration (0002_add_reports). When you do that, your
migration can be broken by future changes to the model -- and this is exactly
the problem you see. South provides "frozen" models -- models whose definition
is fixed at the time the migration was written; this makes sure they fit the
database state when you run the migration.

The immediate fix is to edit the 0002_add_reports migration and remove import
statements for any model. In the migration code, wherever you used
ReportConfig, replace it with orm.ReportConfig -- the frozen model. If you need
to access models for other apps, you can access them as
orm['myapp.ModelName'].

However, if you've made changes to ReportConfig along the line, it is quite
possible that the migration, while it managed to run, did not execute the
intended code (e.g. if some defaults were changed, newer installations would
use the new defaults for the old contents -- this may be what you want, or
not). I'd recommend you to review the changes, and verify that all relevant
databases have expected contents -- at the extreme, if you're all still in
development and want to be on the safe side, just drop and recreate all
databases after you've applied the fix.

For more details about this, look at
http://south.readthedocs.org/en/latest/ormfreezing.html

Hope this helps,
Shai.

Victor Liu

unread,
Oct 17, 2014, 5:38:38 AM10/17/14
to south...@googlegroups.com
Dear Shai

Thanks for your reply. It is very helpful. I noticed that it is not right to import ReportConfig directly in the old code. After I replaced them with orm.ReportConfig, the problem solved. 
Thanks for your assistance again.

Best Regards
Victor Liu
Reply all
Reply to author
Forward
0 new messages