The Digital Agency for International Development

Problem changing primary keys with South in Django

By Chris Wilson on 10 January 2013

I just discovered a problem with primary key changes in South for a Django application.

I had an explicit primary key in my model (a char field). I removed it, so the primary key became the default one supplied by Django.

Using the schemamigration command to generate the migration automatically didn't do everything it should have:

  • the new ID column was not actually set as a primary key in the SQL database;
  • the database table was left with no primary key at all;
  • the schemamigration command prompted me for a default value for the new ID field for existing records

I filed South bug 1200 about this. There's also a workaround in that ticket, in case anyone has the same problem.