1
votes

I have to add a new field to a model and its giving me lots of trouble. So, I tried doing a fake migration, then migrating again, didn't work. Then I tried a couple of other things that didn't work either.

Then I got tired and dropped the south_migrationhistory table from the database, deleted the "migrations" folders from my apps and started again from the beginning. Ran syncdb and "convert to south" on each app, then "migrate" on each app and I got "nothing to migrate" every time.

Now I get the same error I got before: "column does not exist". That is the column I want to add to my table. I don't know why I get this error if I removed the south_migrationhistory table from the database and deleted the "migrations" folders.

Completely lost and worried here. Any help will be appreciated.

1
Is this just in development? What happens if you delete the whole database and do syncdb and a migrate? (remember to back up your db first before making drastic changes)veroxii
Yep its just in development. I guess that would work (deleting the db and then syncdb). Just tried it all again, even ran pip install south --upgrade just in case. Bit it didn't work, still can't add the field the normal way (with South).Alejandro Veintimilla
Okay, what is the field type? Can you post your model before and after the addition of the field?veroxii

1 Answers

3
votes

Let's look at what you said you did:

  1. "convert to south" will create the initial migration and fake the application
  2. "migrate": there will be nothing to migrate, if all you did was convert to south.

So far, it's behaving as expected.

What you really need to do is run "convert to south" with your codebase in the state it was in that matches your database, i.e. with the missing column removed from your models.py

You then need to add your new columns back into the models.py, run python manage.py schemamigration myapp --auto which will generate the SQL statements to add your missing fields, then you need to run the migrate command.

What's going on is that your "convert to south" thinks the missing column already exists. It doesn't.

Another solution is to do nothing further with south and add the missing column via SQL manually into your database. Future deployments with your new south migrations will still work, because the CREATE TABLE statements will contain your missing column.