I have a model called Document, and I want to add a new table, DocumentCluster that sits above it, with a foreign key to Document.
class DocumentCluster(models.Model):
sub_document = models.ForeignKey(Document)
...lots of fields here...
When I add this table using South, I need to fill it in by setting the primary key and the foreign key to the same value.
For example, if I currently have a Document object with a pk of 12, the new DocumentCluster object will have a pk of 12 and a foreign key to Document number 12.
While it may seem strange that we need the DocumentCluster pk values to match the foreign key values there is an important reason. We use the Document pk in our URLs, but after the change the URLs will load a DocumentCluster, not a Document, so we'll need the pk in DocumentCluster to be the same as it was in Document.
Once that's done, I want the PK of the DocumentCluster to be an AutoField, incrementing from the highest value that was migrated.
Can this be done?