Opened 10 years ago
Closed 9 years ago
#24954 closed Bug (duplicate)
Adding an explicit UUID id doesn't change type of ManyToMany fields pointing to it
Reported by: | cloudOver | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Normal | Keywords: | ManyToMany, UUID |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have models with manyToMany field and uuid based primary keys, e.g.:
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.
Attachments (1)
Change History (5)
comment:1 by , 10 years ago
Component: | Database layer (models, ORM) → Migrations |
---|
comment:2 by , 10 years ago
This also applies to changing the primary key of the referenced model; a migration to update the existing column is not detected/generated
comment:3 by , 10 years ago
Summary: | ManyToMany field fails with non-integer ids → Adding an explicit UUID id doesn't change type of ManyToMany fields pointing to it |
---|---|
Triage Stage: | Unreviewed → Accepted |
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).
by , 9 years ago
Attachment: | test_many2many_intermediate_table_not_migrated.diff added |
---|
Many to many intermediate table is not migrated.
comment:4 by , 9 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Duplicate of #25012 as ManyToManyField
uses ForeignKey
under the hood.
The problem refers to migration system. In some cases, Django migration didn't change types of foreign keys in ManyToMany.