Django South - table already exists

前端 未结 8 602
名媛妹妹
名媛妹妹 2020-12-02 03:55

I am trying to get started with South. I had an existing database and I added South (syncdb, schemamigration --initial).

Then, I updated <

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 04:25

    If you have problems with your models not matching your database, like @pielgrzym, and you want to automatically migrate the database to match the latest models.py file (and erase any data that won't be recreated by fixtures during migrate):

    manage.py schemamigration myapp --initial
    manage.py migrate myapp --fake
    manage.py migrate myapp zero
    manage.py migrate myapp
    

    This will only delete and recreate database tables that exist in your latest models.py file, so you may have garbage tables in your database from previous syncdbs or migrates. To get rid of those, precede all these migrations with:

    manage.py sqlclear myapp | manage.py sqlshell
    

    And if that still leaves some CRUFT lying around in your database then you'll have to do an inspectdb and create the models.py file from that (for the tables and app that you want to clear) before doing the sqlclear and then restore your original models.py before creating the --initial migration and migrating to it. All this to avoid messing around with the particular flavor of SQL that your database needs.

提交回复
热议问题