[Django] #33709: Primary key of m2m tables is not migrated to BigAutoField

13 views
Skip to first unread message

Django

unread,
May 14, 2022, 12:32:44 PM5/14/22
to django-...@googlegroups.com
#33709: Primary key of m2m tables is not migrated to BigAutoField
-----------------------------------------+------------------------
Reporter: Jeremy Lainé | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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 |
```

--
Ticket URL: <https://code.djangoproject.com/ticket/33709>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 14, 2022, 12:33:39 PM5/14/22
to django-...@googlegroups.com
#33709: Primary key of m2m tables is not migrated to BigAutoField
-------------------------------+--------------------------------------

Reporter: Jeremy Lainé | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Jeremy Lainé:

Old description:

> 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 |
> ```

New description:

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 |
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33709#comment:1>

Django

unread,
May 16, 2022, 12:14:27 AM5/16/22
to django-...@googlegroups.com
#33709: Primary key of m2m tables is not migrated to BigAutoField
-------------------------------------+-------------------------------------

Reporter: Jeremy Lainé | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => New feature


Comment:

Duplicate of #32674, see also a note in
[https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD docs].

--
Ticket URL: <https://code.djangoproject.com/ticket/33709#comment:2>

Django

unread,
May 16, 2022, 1:03:26 AM5/16/22
to django-...@googlegroups.com
#33709: Primary key of m2m tables is not migrated to BigAutoField
-------------------------------------+-------------------------------------
Reporter: Jeremy Lainé | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jeremy Lainé):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/33709#comment:3>

Reply all
Reply to author
Forward
0 new messages