[Django] #34382: DEFAULT_AUTO_FIELD ignored for new models

16 views
Skip to first unread message

Django

unread,
Mar 3, 2023, 5:33:55 AM3/3/23
to django-...@googlegroups.com
#34382: DEFAULT_AUTO_FIELD ignored for new models
------------------------------------------+------------------------
Reporter: Alberto Donato | 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 |
------------------------------------------+------------------------
Setting the value of `DEFAULT_AUTO_FIELD` to e.g. `AutoField` seems to be
ignored when generating migrations for new models.

A simple reproducer is to create a new project, change the setting as
follows:

{{{
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
}}}

and adding a simple model such as:

{{{
class SampleModel(models.Model):
name = models.TextField(unique=True)
}}}


After running `./manage.py makemigrations` the following migration is
generated:

{{{
class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='SampleModel',
fields=[
('id', models.BigAutoField(auto_created=True,
primary_key=True, serialize=False, verbose_name='ID')),
('name', models.TextField(unique=True)),
],
),
]
}}}


Same behavior can be reproduced both in 3.2 and 4.1.7.

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

Django

unread,
Mar 3, 2023, 5:43:26 AM3/3/23
to django-...@googlegroups.com
#34382: DEFAULT_AUTO_FIELD ignored for new models
-------------------------------------+-------------------------------------

Reporter: Alberto Donato | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution: invalid

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: => invalid
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for this report, however it works for me. You can check
`AppConfig.default_auto_field` in your apps, it's probably set to
`BigAutoField`, see
[https://docs.djangoproject.com/en/stable/topics/db/models/#automatic-
primary-key-fields "Automatic primary key fields"] for more details.

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

Reply all
Reply to author
Forward
0 new messages