[Django] #32805: makemigrations seems to generate an unnecessary AlterField

14 views
Skip to first unread message

Django

unread,
Jun 1, 2021, 10:00:18 AM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
-------------------------------------+-------------------------------------
Reporter: Matthew | Owner: nobody
Cornell |
Type: | Status: new
Uncategorized |
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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!

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

Django

unread,
Jun 1, 2021, 10:01:23 AM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
-------------------------------------+-------------------------------------
Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by Matthew Cornell):

* Attachment "forecast.py" added.

Django

unread,
Jun 1, 2021, 10:01:44 AM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
-------------------------------------+-------------------------------------
Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by Matthew Cornell):

* Attachment "0017_forecast_issued_at.py" added.

Django

unread,
Jun 1, 2021, 10:01:55 AM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
-------------------------------------+-------------------------------------
Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by Matthew Cornell):

* Attachment "0018_auto_20210601_0946.py" added.

Django

unread,
Jun 1, 2021, 11:36:31 AM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
-------------------------------------+-------------------------------------
Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 3.1
(models, ORM) |
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
-------------------------------------+-------------------------------------

Comment (by 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?

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

Django

unread,
Jun 1, 2021, 11:41:58 AM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
---------------------------------+--------------------------------------

Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: closed
Component: Migrations | Version: 3.1
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: Database layer (models, ORM) => Migrations


Comment:

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.

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

Django

unread,
Jun 1, 2021, 1:10:53 PM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
---------------------------------+--------------------------------------
Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: closed
Component: Migrations | Version: 3.1
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
---------------------------------+--------------------------------------

Comment (by Matthew Cornell):

Genius! Thanks very much.

Replying to [comment:1 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?

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

Django

unread,
Jun 1, 2021, 1:15:40 PM6/1/21
to django-...@googlegroups.com
#32805: makemigrations seems to generate an unnecessary AlterField
---------------------------------+--------------------------------------
Reporter: Matthew Cornell | Owner: nobody
Type: Uncategorized | Status: closed
Component: Migrations | Version: 3.1
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
---------------------------------+--------------------------------------

Comment (by Matthew Cornell):

Thank you. Apologies.

Replying to [comment:2 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32805#comment:4>

Reply all
Reply to author
Forward
0 new messages