#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)
Change History (7)
by , 3 years ago
Attachment: | forecast.py added |
---|
by , 3 years ago
Attachment: | 0017_forecast_issued_at.py added |
---|
by , 3 years ago
Attachment: | 0018_auto_20210601_0946.py added |
---|
follow-up: 3 comment:1 by , 3 years ago
follow-up: 4 comment:2 by , 3 years ago
Component: | Database layer (models, ORM) → Migrations |
---|---|
Resolution: | → invalid |
Status: | new → closed |
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.
comment:3 by , 3 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'sdefault=None
to see if still 0018 is produced by makemigrations?
comment:4 by , 3 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 theAlterField
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 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?