Opened 9 years ago

Closed 8 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)

test_many2many_intermediate_table_not_migrated.diff (4.0 KB ) - added by Alexander 8 years ago.
Many to many intermediate table is not migrated.

Download all attachments as: .zip

Change History (5)

comment:1 by cloudOver, 9 years ago

Component: Database layer (models, ORM)Migrations

The problem refers to migration system. In some cases, Django migration didn't change types of foreign keys in ManyToMany.

comment:2 by synotna, 9 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 Tim Graham, 9 years ago

Summary: ManyToMany field fails with non-integer idsAdding an explicit UUID id doesn't change type of ManyToMany fields pointing to it
Triage Stage: UnreviewedAccepted

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 Alexander, 8 years ago

Many to many intermediate table is not migrated.

comment:4 by Simon Charette, 8 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #25012 as ManyToManyField uses ForeignKey under the hood.

Note: See TracTickets for help on using tickets.
Back to Top