Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#33709 closed New feature (duplicate)

Primary key of m2m tables is not migrated to BigAutoField

Reported by: Jeremy Lainé Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jeremy Lainé)

I am trying to upgrade an existing application's models to use only "bigint" primary keys on postgresql. To do this I changed DEFAULT_AUTO_FIELD to BigAutoField, generated the migrations then applied them.

The tables for my explicitly defined models get upgraded correctly. The many-to-many intermediate tables on the other hand still have an "integer" primary key, with the 32bit limit I'm trying to avoid.

The following model are sufficient to reproduce the issue:

class Book(models.Model):
    name = models.CharField(max_length=255)
    tags = models.ManyToManyField("Tag")


class Tag(models.Model):
    name = models.CharField(max_length=255)

The resulting schema for the testapp_book_tags looks like:

test=> \d testapp_book_tags;
                             Table "public.testapp_book_tags"
 Column  |  Type   | Collation | Nullable |                    Default                    
---------+---------+-----------+----------+-----------------------------------------------
 id      | integer |           | not null | nextval('testapp_book_tags_id_seq'::regclass)
 book_id | bigint  |           | not null | 
 tag_id  | bigint  |           | not null |

Change History (3)

comment:1 by Jeremy Lainé, 2 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 2 years ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: duplicate
Status: newclosed
Type: UncategorizedNew feature

Duplicate of #32674, see also a note in DEFAULT_AUTO_FIELD docs.

comment:3 by Jeremy Lainé, 2 years ago

Sorry for the noise, I obviously missed the existing issue!

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