Code

Ticket #13987: 13987_primary_key_fix_2.diff

File 13987_primary_key_fix_2.diff, 661 bytes (added by Aramgutang, 4 years ago)

2nd possible fix: fetching the field for current model when "_preparing" it.

Line 
1Index: django/db/models/options.py
2===================================================================
3--- django/db/models/options.py (revision 13444)
4+++ django/db/models/options.py (working copy)
5@@ -113,6 +113,9 @@
6                 # Promote the first parent link in lieu of adding yet another
7                 # field.
8                 field = self.parents.value_for_index(0)
9+                already_created = [fld for fld in self.local_fields if fld.name == field.name]
10+                if already_created:
11+                    field = already_created[0]
12                 field.primary_key = True
13                 self.setup_pk(field)
14             else: