Django 1.7 migration error

為{幸葍}努か 提交于 2019-12-02 08:51:22

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!