[Answer]-Django 1.7 migration error

1👍

What follows is a hack which is so easy and so nasty to apply while developing or even better while learning other parts of django and you just need a quick solution to get the work done … in other words, a sin … like bitter chocolate.

First of all, I keep my database data in a json file in case I need to rebuild it:

./manage.py dumpdata --exclude auth.permission --exclude contenttypes  --exclude reversion --exclude admin.LogEntry --indent 2 > db.json

When I change something in my models and I see that migrations start throwing errors, I try deleting everything regarding the application under consideration from the database (or -even better- the whole database) and then I rebuild it:

$./manage.py migrate <myapp1> zero #No need for this if the whole database is destroyed
$rm -Rf <myapp(s/1)>/migrations/*
$./manage.py makemigrations <myapp1>( <myapp2> ... <myappN>)
$./manage.py migrate <myapp(s/1)>
$./manage.py loaddata ...

This is most of the times faster than debugging the error. Sometimes, however, causes more problems than it is supposed to solve. This is when the database json file comes handy.

A pittiful solution but this is my revenge when all those details make me very angry and I enjoy it.

Leave a comment