Opened 4 years ago

Closed 4 years ago

#26346 closed Bug (duplicate)

Error in makemigrations while changing DateTimeField default value from timezone aware datetime to naive

Reported by: shahzebiam Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords: migrations, datetimefield migration, makemigrations, default date
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a DateTimeField in a model in which i have given a default value of When i changed the default value to and ran the makemigrations command, it gave me an error in

Traceback (most recent call last):
  File "", line 10, in <module>
  File "C:\Python27\lib\site-packages\django\core\management\", line 354, in execute_from_command_line
  File "C:\Python27\lib\site-packages\django\core\management\", line 346, in execute
  File "C:\Python27\lib\site-packages\django\core\management\", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\", line 445, in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\", line 125, in handle
  File "C:\Python27\lib\site-packages\django\db\migrations\", line 43, in changes
    changes = self._detect_changes(convert_apps, graph)
  File "C:\Python27\lib\site-packages\django\db\migrations\", line 186, in _detect_changes
  File "C:\Python27\lib\site-packages\django\db\migrations\", 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.

Change History (1)

comment:1 Changed 4 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #24822

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