Making Django App Reset South-Aware
01 Nov 2012
Today I needed to reset an app in a Django site I’m working on. The problem is that I’m using South on this app to track database schema migrations. Since I’m using South, I can’t just do:
python manage.py reset myapp
because that doesn’t reset the South migration history. One solution I found floating around on the web got me pretty close, but it also coalesced all of my existing migrations into a single “initial” migration, which I didn’t want.
All I need to do to accomplish what I want (reset an app while maintaining existing migrations) is:
python manage.py sqlclear myapp | python manage.py dbshell # ...edit south.models.MigrationHistory... python manage.py migrate myapp
The Management Command
To make things a little easier, I’ve packaged the first two steps up into a Django management command so that I can reset a South app like so:
python manage.py south_clear myapp python manage.py migrate myapp
Here’s the management command:
Drop this in a
management/commands directory (if you’ve never done
that before, see
and you’re good to go!
blog comments powered by Disqus
- GitHub Profile
- Stack Overflow Careers Profile
- Stack Overflow Profile
- G+ Profile
- PGP Public Key
- Rafty -- Ripper and Friggin Transcoder, Y'all
- Make Readme Markdown
- Diffview Mode
- Indent Hints Mode
- Track That Thing
- Co-Founder & CTO of Directangular, LLC.
- Previously: Linux Kernel development for QuIC. Some of my work (a little stale) is available on the Code Aurora Forum, here, here, here, and here.
- My nerd hobby: Creating and contributing to a variety of Open Source projects. See my GitHub profile.