Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32805 closed Uncategorized (invalid)

makemigrations seems to generate an unnecessary AlterField

Reported by: Matthew Cornell Owned by: nobody
Component: Migrations Version: 3.1
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

I have a model that's evolved over time. I needed to hand-code my last migration ( migrations/0017_forecast_issued_at.py ) to migrate existing data from a DateField to a DateTimeField. However, when I then run makemigrations ( migrations/0018_auto_20210601_0946.py ), it generates what looks to me like a redundant AlterField operation where it wants to set the new DateTimeField's db_index=True even though it's already True in the previous (0017) migration. I've attached the model file ( models/forecast.py ) plus the two migration files. Questions: Is this behavior expected? Thank you!

Attachments (3)

forecast.py (1.2 KB ) - added by Matthew Cornell 4 years ago.
0017_forecast_issued_at.py (2.1 KB ) - added by Matthew Cornell 4 years ago.
0018_auto_20210601_0946.py (400 bytes ) - added by Matthew Cornell 4 years ago.

Download all attachments as: .zip

Change History (7)

by Matthew Cornell, 4 years ago

Attachment: forecast.py added

by Matthew Cornell, 4 years ago

Attachment: 0017_forecast_issued_at.py added

by Matthew Cornell, 4 years ago

Attachment: 0018_auto_20210601_0946.py added

comment:1 by Christos Georgiou, 4 years ago

In 0017 you AlterField to:
field=models.DateTimeField(db_index=True, default=None, null=False),
which doesn't make much sense (null=False and yet default=None).
Have you tried to remove the AlterField's default=None to see if still 0018 is produced by makemigrations?

comment:2 by Mariusz Felisiak, 4 years ago

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

Please don't use Trac as a support channel, this is a manually created migration. To avoid creation of 0018_auto_20210601_0946.py​ you can change the AlterField to the:

        migrations.AlterField(
            model_name='forecast',
            name='issued_at',
            field=models.DateTimeField(db_index=True),
        ),

default=None is not the same as not providing a default.

Closing per TicketClosingReasons/UseSupportChannels.

in reply to:  1 comment:3 by Matthew Cornell, 4 years ago

Genius! Thanks very much.

Replying to Christos Georgiou:

In 0017 you AlterField to:
field=models.DateTimeField(db_index=True, default=None, null=False),
which doesn't make much sense (null=False and yet default=None).
Have you tried to remove the AlterField's default=None to see if still 0018 is produced by makemigrations?

in reply to:  2 comment:4 by Matthew Cornell, 4 years ago

Thank you. Apologies.

Replying to Mariusz Felisiak:

Please don't use Trac as a support channel, this is a manually created migration. To avoid creation of 0018_auto_20210601_0946.py​ you can change the AlterField to the:

        migrations.AlterField(
            model_name='forecast',
            name='issued_at',
            field=models.DateTimeField(db_index=True),
        ),

default=None is not the same as not providing a default.

Closing per TicketClosingReasons/UseSupportChannels.

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