[Django] #21905: django migrate/makemigrations detects changes when none were made

62 views
Skip to first unread message

Django

unread,
Jan 29, 2014, 5:56:09 PM1/29/14
to django-...@googlegroups.com
#21905: django migrate/makemigrations detects changes when none were made
-----------------------------+-------------------------------------------
Reporter: taishi@… | Owner:
Type: New feature | Status: new
Component: Migrations | Version: 1.7-alpha-1
Severity: Normal | Keywords: migrate, migrations, datetime
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------------
I'm running a model which contains datetime.now() as default value and
django keeps thinking that I altered that field.
So everytime I run migrates I get:
Running migrations:
No migrations needed.
Your models have changes that are not yet reflected in a migration, and
so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run
'manage.py migrate' to apply them.

If I run makemigrations (once, twice, 20 times) it will always output:
Migrations for 'acb_coins':
0003_auto_20140129_1947.py:
- Alter field last_sync on coin

Model:
class Coin(models.Model):
name = models.CharField(max_length=80)
short_name = models.CharField(max_length=4)
rpc_address = models.CharField(max_length=30)
rpc_port = models.IntegerField(max_length=5)
balance = models.DecimalField(decimal_places=10, max_digits=15)
last_sync = models.DateTimeField(default=datetime.now())

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

Django

unread,
Jan 29, 2014, 5:58:45 PM1/29/14
to django-...@googlegroups.com
#21905: django migrate/makemigrations detects changes when none were made
-------------------------------------+-------------------------------------

Reporter: taishi@… | Owner:
Type: New feature | Status: new
Component: Migrations | Version:
Severity: Normal | 1.7-alpha-1
Keywords: migrate, | Resolution:
migrations, datetime | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by matt@…):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

You don't want to be using datetime.now(): that gets evaluated at the time
the module is imported.

You'll want to use datetime.now

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

Django

unread,
Jan 29, 2014, 6:04:46 PM1/29/14
to django-...@googlegroups.com
#21905: django migrate/makemigrations detects changes when none were made
-------------------------------------+-------------------------------------

Reporter: taishi@… | Owner:
Type: New feature | Status: new
Component: Migrations | Version:
Severity: Normal | 1.7-alpha-1
Keywords: migrate, | Resolution:
migrations, datetime | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MarkusH):

* cc: info@… (added)


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

Django

unread,
Jan 29, 2014, 6:06:16 PM1/29/14
to django-...@googlegroups.com
#21905: django migrate/makemigrations detects changes when none were made
-------------------------------------+-------------------------------------

Reporter: taishi@… | Owner:
Type: New feature | Status: new
Component: Migrations | Version:
Severity: Normal | 1.7-alpha-1
Keywords: migrate, | Resolution:
migrations, datetime | Triage Stage:
Has patch: 0 | Unreviewed
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by taishi@…):

matt@ comment worked

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

Django

unread,
Jan 29, 2014, 6:19:48 PM1/29/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody

Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by MarkusH):

* keywords: migrate, migrations, datetime => check
* owner: => nobody
* component: Migrations => Core (Other)


Comment:

Given the confusion about passing `default` a `datetime` object instead of
a callable (which solves the problem), I'd like to propose the idea to add
a check to Django's check framework to make users aware of these problems
that might occur over the time when using `datetime.now()` instead of
`datetime.now`.

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

Django

unread,
Jan 30, 2014, 4:16:42 AM1/30/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by mjtamlyn):

* stage: Unreviewed => Accepted


Comment:

Accepted in principle, but I'm not sure how this could be implemented.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:5>

Django

unread,
Jan 30, 2014, 8:50:38 AM1/30/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------

Comment (by matheusrosa):

Why don't you use {{{auto_now=True}}} ? Every time you call save(), the
{{{last_sync}}} field gets updated with the latest date and time.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:6>

Django

unread,
Jan 30, 2014, 7:01:57 PM1/30/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
------------------------------+---------------------------------------

Comment (by russellm):

@mjtamlyn - This could be a job for the check framework. We could add a
field-level check on the value of default - if the value of default is
within some tolerance of now (e.g., within 10 seconds), raise a warning.
Since the checks are run almost immediately after the model is loaded, any
usage of datetime.now() would return the current date time (or as close as
practical). The only way this check would fail would be if someone
actually wanted *now*; so, we add it as a warning that can be silenced.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:7>

Django

unread,
Jan 30, 2014, 7:03:13 PM1/30/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by russellm):

* easy: 0 => 1


Comment:

To that end, it's a pretty easy fix; marking as such.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:8>

Django

unread,
Jan 30, 2014, 7:15:38 PM1/30/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------

Comment (by MarkusH):

Sounds like a plan, russellm. Do we want to get it into 1.7?

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:9>

Django

unread,
Jan 30, 2014, 8:12:07 PM1/30/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------

Comment (by russellm):

@MarkusH - No reason it couldn't be in 1.7 - it's a minor fix. We just
need a patch :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:10>

Django

unread,
Feb 9, 2014, 6:01:14 AM2/9/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: closed

Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution: duplicate

Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by rkstapenhurst):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #21638

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:11>

Django

unread,
Feb 9, 2014, 6:14:06 AM2/9/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: nobody
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by MarkusH):

* status: closed => new
* resolution: duplicate =>


Comment:

This ticket is not a duplicate at all. The intention is to add a check
command warning a user that `now()` instead of `now` as a field's default
value is probably not what they want.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:12>

Django

unread,
Feb 10, 2014, 4:14:45 AM2/10/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: mamun
Type: New feature | Status: assigned

Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------
Changes (by mamun):

* owner: nobody => mamun
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:13>

Django

unread,
Feb 15, 2014, 3:45:13 PM2/15/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
------------------------------+---------------------------------------
Reporter: taishi@… | Owner: mamun
Type: New feature | Status: assigned
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+---------------------------------------

Comment (by AeroNotix):

@mamun patch incoming?

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:14>

Django

unread,
Feb 22, 2014, 6:12:31 AM2/22/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
----------------------------------+---------------------------------------
Reporter: taishi@… | Owner: MarkusH

Type: New feature | Status: assigned
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check nlsprint14 | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+---------------------------------------
Changes (by MarkusH):

* keywords: check => check nlsprint14
* owner: mamun => MarkusH


--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:15>

Django

unread,
Feb 22, 2014, 8:34:11 AM2/22/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
----------------------------------+---------------------------------------
Reporter: taishi@… | Owner: MarkusH
Type: New feature | Status: assigned
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check nlsprint14 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+---------------------------------------
Changes (by MarkusH):

* has_patch: 0 => 1


Comment:

Here's the pull request: https://github.com/django/django/pull/2346

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:16>

Django

unread,
May 17, 2014, 6:09:23 AM5/17/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
----------------------------------+---------------------------------------
Reporter: taishi@… | Owner: MarkusH
Type: New feature | Status: closed

Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution: fixed

Keywords: check nlsprint14 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+---------------------------------------
Changes (by Markus Holtermann <info@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"9d8c73f6a1c636853a5c5013f21985d702b2301b"]:
{{{
#!CommitTicketReference repository=""
revision="9d8c73f6a1c636853a5c5013f21985d702b2301b"
Fixed #21905 -- Add info message if DateField or TimeField use a fixed
value
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:17>

Django

unread,
May 17, 2014, 6:09:24 AM5/17/14
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
----------------------------------+---------------------------------------
Reporter: taishi@… | Owner: MarkusH
Type: New feature | Status: closed
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution: fixed
Keywords: check nlsprint14 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+---------------------------------------

Comment (by Florian Apolloner <florian@…>):

In [changeset:"11932e978f980846d2c3326ff070ece7e65bf75c"]:
{{{
#!CommitTicketReference repository=""
revision="11932e978f980846d2c3326ff070ece7e65bf75c"
Merge pull request #2346 from Markush2010/ticket21905

Fixed #21905 -- Add info message if DateField or TimeField use a fixed
value
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:18>

Django

unread,
Jun 9, 2016, 6:35:43 PM6/9/16
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
----------------------------------+---------------------------------------
Reporter: taishi@… | Owner: MarkusH
Type: New feature | Status: new
Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: check nlsprint14 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+---------------------------------------
Changes (by lig):

* status: closed => new

* resolution: fixed =>


Comment:

The implementation contains a bug. Here is the code that probably fixes it
https://github.com/django/django/pull/6749

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:19>

Django

unread,
Jun 9, 2016, 7:40:33 PM6/9/16
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
----------------------------------+---------------------------------------
Reporter: taishi@… | Owner: MarkusH
Type: New feature | Status: closed

Component: Core (Other) | Version: 1.7-alpha-1
Severity: Normal | Resolution: fixed

Keywords: check nlsprint14 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------+---------------------------------------
Changes (by charettes):

* status: new => closed
* resolution: => fixed


Comment:

Please file a new bug report instead of reopening this old fixed one.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:20>

Django

unread,
Jul 31, 2021, 2:16:14 PM7/31/21
to django-...@googlegroups.com
#21905: Add check for default=now() on Date/Time/DateTimeFields
-------------------------------------+-------------------------------------
Reporter: taishi@… | Owner: Markus
| Holtermann

Type: New feature | Status: closed
Component: Core (Other) | Version:
| 1.7-alpha-1
Severity: Normal | Resolution: fixed
Keywords: check nlsprint14 | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

> The implementation contains a bug. Here is the code that probably fixes
it ​https://github.com/django/django/pull/6749

FYI, this issue was recently rediscovered and fixed as part of #32966.

--
Ticket URL: <https://code.djangoproject.com/ticket/21905#comment:21>

Reply all
Reply to author
Forward
0 new messages