tadasajon
tadasajon

Reputation: 14836

Django - South migration - how do I break a large migration down into several smaller migrations? How can I make South smarter?

I have made several adjustments to my database schema and it now time to run:

> ./manage.py schemamigration --auto my_app

However, South is raising various objections about setting defaults for some fields, etc. It also isn't picking up on the fact that I have renamed a certain column in one of my tables - it thinks I am dropping one column and adding another, when in fact I have just renamed a single column. How can I make South smarter? Also, is it possible to break this migration down into several smaller steps?

Upvotes: 2

Views: 97

Answers (3)

Kevin Christopher Henry
Kevin Christopher Henry

Reputation: 48902

You've mentioned two issues: warning messages about defaults, and the inability to detect your renamed column.

Regarding the first, South is probably doing the right thing. If you add a column that is non-NULL, South has to put something in the database, so it prompts you to say what that something should be be.

Regarding the second, South unfortunately doesn't handle column renaming. The solution is to create your own migration and use db.rename_column. See this answer.

Although it makes sense to make schema changes in small increments, it doesn't actually sound like South is getting confused by the magnitude of your changes. Given where you are now, I would suggest first undoing the column name change and running schemamigration --auto to handle all your other changes. I suspect this will work fine. Then create a new migration to do the column rename.

Upvotes: 1

Nick Rempel
Nick Rempel

Reputation: 3022

When you create a new model, you can run south once before adding an attributes. This will create the table in one step. Then, when you make changes, change one model at a time and create migrations for one table at a time.

By doing this, I find the migrations are much cleaner.

Upvotes: 0

dm03514
dm03514

Reputation: 55922

I find it helpful to make a migration after every single change I make to model definitions, not 1 large migration for multiple changes, lots of smaller migrations provide more granularity and its easier to see when 1 migration/change doesn't work opposed to trying to debug, x changes at one time, although this is something that probably wont help you in your current situation

Remember if things get too crazy, you could remove souths management of your app, and start fresh with migrations using your current models state

Upvotes: 0

Related Questions