Modify ↓
Ticket #384 (closed defect: fixed)
Adding a OneToOne relation fails
| Reported by: | david@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.7 |
| Component: | migrations | Version: | 0.7-pre |
| Keywords: | Cc: |
Description
My migration basically looks like this:
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Account.auth_user'
db.add_column(u'account', 'auth_user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True, null=True), keep_default=False)
# Snipped out the frozen ORM from the bottom.
Which looks pretty simple to me, but when it runs I get this error:
django.db.utils.DatabaseError: constraint "auth_user_id_refs_id_1f3e59b6" for relation "account" already exists!
After much fiddling around it seems to me that the SQL that adds the FK constraint is being added to the deferred_sql list and is executed directly, so this results in it being executed twice.
I'm not entirely sure what the correct behaviour should be, but I have a patch that fixes it by checking if the sql has been deferred at the time that it would be executed.
This also failed in a very similar way when I changed the field to a unique ForeignKey? field.
Attachments
Change History
Changed 3 years ago by david@…
- Attachment south-384-fix.diff added
comment:2 Changed 3 years ago by andrew
- Status changed from assigned to closed
- Resolution set to fixed
Fixed in [a72454a60f66].
Note: See
TracTickets for help on using
tickets.

Proposed patch to fix #384