{{{
class SomeModel(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
editable=False)
blockers = models.ManyToManyField('self', symmetrical=False,
blank=True)
....
}}}
In 1.8 django creates new table, which has integer-based identifier for
ManyToMany relationship:
{{{
describe overCluster_somemodel_blockers;
+--------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| from_somemodel_id | int(11) | NO | MUL | NULL | |
| to_somemodel_id | int(11) | NO | MUL | NULL | |
+--------------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
}}}
Foreign fields from that additional table fails (integer field points to
uuid fields). The same problem exists with string based id. I haven't
found that bug in sqlite backend.
--
Ticket URL: <https://code.djangoproject.com/ticket/24954>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Database layer (models, ORM) => Migrations
* needs_tests: => 0
* needs_docs: => 0
Comment:
The problem refers to migration system. In some cases, Django migration
didn't change types of foreign keys in ManyToMany.
--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:1>
Comment (by synotna):
This also applies to changing the primary key of the referenced model; a
migration to update the existing column is not detected/generated
--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:2>
* stage: Unreviewed => Accepted
Comment:
I could reproduce this with an initial model (implicit `AutoField` `id`):
{{{
class SomeModel(models.Model):
blockers = models.ManyToManyField('self', symmetrical=False,
blank=True)
}}}
then adding an explicit `id` as `id = models.UUIDField(primary_key=True,
default=uuid.uuid4, editable=False)`. The `from_X_id` and `to_X_id` fields
in the many to many table where still 'integer' type (SQLite).
--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:3>
* Attachment "test_many2many_intermediate_table_not_migrated.diff" added.
Many to many intermediate table is not migrated.
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #25012 as `ManyToManyField` uses `ForeignKey` under the hood.
--
Ticket URL: <https://code.djangoproject.com/ticket/24954#comment:4>