Question

I had a model that defined its own primary key. I removed this primary key, South then rightly added in the default Django "id" key in a schemamigration/migrate.

When trying to create instances of the model (through the admin interface or otherwise), I get:

NOT NULL constraint failed: app_myModel.id

The forwards method in the migration says:

db.add_column(u'app_myModel', u'id',
                  self.gf('django.db.models.fields.AutoField')(default=1, primary_key=True),
                  keep_default=False)

But the schema (sqlite3) is:

 "id" integer NOT NULL);

That doesn't look like an AUTOINCREMENT field to me. Not sure how to recover this via migrations, and don't really want to anything that I couldn't do in production if it happened there.

What's happened? What's the fix?

Thanks in advance.

Was it helpful?

Solution

It seems it must be a bug in South, to fix it, I did the following:

  • Rolled back to 0004, the problem was at 0006
  • Deleted 0006
  • Ran ./manage schemamigration app --auto --update , updating 0005
  • Migrated to 0005

The table was made in 0005, don't know if this is significant. It may be you need to migrate backwards to the migration that created the table then update that migration so it can detect the schema correctly. To quote South's primary author Andrew Godwin, discussing primary keys in South:

... that codebase has moved several grown men to tears

It appears the author is aware of the issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top