mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #21954: Raise nice error when serializing datetimes with timezones
This commit is contained in:
@@ -212,7 +212,12 @@ class MigrationWriter(object):
|
||||
strings.append((k_string, v_string))
|
||||
return "{%s}" % (", ".join("%s: %s" % (k, v) for k, v in strings)), imports
|
||||
# Datetimes
|
||||
elif isinstance(value, (datetime.datetime, datetime.date)):
|
||||
elif isinstance(value, datetime.datetime):
|
||||
if value.tzinfo is not None:
|
||||
raise ValueError("Cannot serialize datetime values with timezones. Either use a callable value for default or remove the timezone.")
|
||||
return repr(value), set(["import datetime"])
|
||||
# Dates
|
||||
elif isinstance(value, datetime.date):
|
||||
return repr(value), set(["import datetime"])
|
||||
# Settings references
|
||||
elif isinstance(value, SettingsReference):
|
||||
|
||||
Reference in New Issue
Block a user