Django South - table already exists

前端 未结 8 562
名媛妹妹
名媛妹妹 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:30

    Although the table "myapp_tablename" already exists error stop raising after I did ./manage.py migrate myapp --fake, the DatabaseError shows no such column: myapp_mymodel.added_field.

    Got exactly the same problem!

    1.Firstly check the migration number which is causing this. Lets assume it is: 0010.

    2.You need to:

    ./manage.py schemamigration myapp --add-field MyModel.added_field
    ./manage.py migrate myapp
    

    if there is more than one field missing you have to repeat it for each field.

    3.Now you land with a bunch of new migrations so remove their files from myapp/migrations (0011 and further if you needed to add multiple fields).

    4.Run this:

    ./manage.py migrate myapp 0010
    

    Now try ./manage.py migrate myapp

    If it doesn't fail you're ready. Just doublecheck if any field's aren't missing.

    EDIT:

    This problem can also occur when you have a production database for which you install South and the first, initial migration created in other enviorment duplicates what you already have in your db. The solution is much easier here:

    1. Fake the first migration:

      ./manage migrate myapp 0001 --fake

    2. Roll with the rest of migrations:

      ./manage migrate myapp

    0 讨论(0)
  • 2020-12-02 04:31

    Perform these steps in order may help you:

    1) python manage.py schemamigration apps.appname --initial

    Above step creates migration folder as default.

    2) python manage.py migrate apps.appname --fake

    generates a fake migration.

    3) python manage.py schemamigration apps.appname --auto

    Then you can add fields as you wish and perform the above command.

    4) python manage.py migrate apps.appname

    0 讨论(0)
提交回复
热议问题