[Django] #26346: Error in makemigrations while changing DateTimeField default value from timezone aware datetime to naive datetime.now()

6 views
Skip to first unread message

Django

unread,
Mar 11, 2016, 5:49:04 AM3/11/16
to django-...@googlegroups.com
#26346: Error in makemigrations while changing DateTimeField default value from
timezone aware datetime to naive datetime.now()
-------------------------+-------------------------------------------------
Reporter: | Owner: nobody
shahzebiam |
Type: Bug | Status: new
Component: | Version: 1.8
Migrations | Keywords: migrations, datetimefield
Severity: Normal | migration, makemigrations, default date
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
I have a DateTimeField in a model in models.py which i have given a
default value of django.utils.timezone.now(). When i changed the default
value to datetime.datetime.now() and ran the makemigrations command, it
gave me an error in autodetector.py

{{{
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 354, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
line 346, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py",
line 394, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python27\lib\site-packages\django\core\management\base.py",
line 445, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-
packages\django\core\management\commands\makemigrations.py", line 125, in
handle
migration_name=self.migration_name,
File "C:\Python27\lib\site-
packages\django\db\migrations\autodetector.py", line 43, in changes
changes = self._detect_changes(convert_apps, graph)
File "C:\Python27\lib\site-
packages\django\db\migrations\autodetector.py", line 186, in
_detect_changes
self.generate_altered_fields()
File "C:\Python27\lib\site-
packages\django\db\migrations\autodetector.py", line 850, in
generate_altered_fields
if old_field_dec != new_field_dec:
TypeError: can't compare offset-naive and offset-aware datetimes
}}}

as far as i know it is trying to compare a timezone aware date with a
simple datetime which will not be possible for datetime objects.

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

Django

unread,
Mar 11, 2016, 6:35:55 AM3/11/16
to django-...@googlegroups.com
#26346: Error in makemigrations while changing DateTimeField default value from
timezone aware datetime to naive datetime.now()
-------------------------------------+-------------------------------------
Reporter: shahzebiam | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Normal | Resolution: duplicate
Keywords: migrations, | Triage Stage:
datetimefield migration, | Unreviewed
makemigrations, default date |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

Duplicate of #24822

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

Reply all
Reply to author
Forward
0 new messages