Django & South: Adding new field but DatabaseError occurs “table already exists”

≡放荡痞女 提交于 2019-12-03 13:59:14

问题


In trying to add a new field to a preexisting Model/table, I get a DatabaseError with 'table already exists.' I have run migrations before this one so I am a bit puzzled why adding a new field would pop up this error.

Commands executed:

python manage.py schemamigration app --auto
python manage.py migrate app

Previous SO questions like this were answered with faking a migration.

python manage.py migrate app --fake
python manage.py migrate app

The problem that arises from this is that the column is not created. So when you runserver, you will see a DatabaseError 'no such column'.

As far as my model, I am only adding a CharField.

Thanks in advance for your help-


回答1:


You need to do schemamigration app --initial first without your new field, then migrate app --fake 0001 (or whichever migration number it returned) to set the south database to that state (tables already created).

Add your new field, then run schemamigration myapp --auto, then migrate.




回答2:


I commented out the field, ran schemamigration, then migrate. Uncommented out the field, ran schemamigration, then migrate and it worked. Not sure what I was doing wrong.




回答3:


This happens when you doing something on migration and did not let south knows about it.

If you looking at the south_* table in the database, you will find-out south keeps logs about db migrations in the database. The common way is to faking the migration. There is a fake argument for the South.

here you can find out what is all about: http://south.readthedocs.org/en/latest/commands.html#options



来源:https://stackoverflow.com/questions/10769644/django-south-adding-new-field-but-databaseerror-occurs-table-already-exists

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