#34382 closed Uncategorized (invalid)

DEFAULT_AUTO_FIELD ignored for new models

Reported by: Alberto Donato 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

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.

Change History (1)

comment:1 by Mariusz Felisiak, 20 months ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: invalid
Status: newclosed

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 Automatic primary key fields for more details.

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