AttributeError: type object 'datetime.date' has no attribute 'utcnow'

1,397 views
Skip to first unread message

David Spector

unread,
Dec 14, 2011, 2:53:44 PM12/14/11
to South Users
Hi

Am trying to create a migration that replaces a couple of datetime
fields using a new abstract class, but when I try to have south set up
the schema migration I get a crash because south doesn't seem to know
about the datetime module. Any ideas on how to get around this?

tia,
David

here's the trace:

%python manage.py schemamigration --auto schoolinfo
extended_model_timestamps
? The field 'CourseInstance.modified_at' does not have a default
specified, yet is NOT NULL.
? Since you are removing this field, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now, and add a default to the field in models.py
? 2. Specify a one-off value to use for existing columns now
? 3. Disable the backwards migration by raising an exception.
? Please select a choice: 2
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g.
datetime.date.today()
>>> datetime.date.utcnow()
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Python/2.7/site-packages/django/core/management/
__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/
__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/
base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/
base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/south/management/commands/
schemamigration.py", line 141, in handle
action = action_class(**params)
File "/Library/Python/2.7/site-packages/south/creator/actions.py",
line 228, in __init__
self.deal_with_not_null_no_default(self.field, self.field_def)
File "/Library/Python/2.7/site-packages/south/creator/actions.py",
line 170, in deal_with_not_null_no_default
self.add_one_time_default(field, field_def)
File "/Library/Python/2.7/site-packages/south/creator/actions.py",
line 186, in add_one_time_default
result = eval(code, {}, {"datetime": datetime})
File "<string>", line 1, in <module>
AttributeError: type object 'datetime.date' has no attribute 'utcnow'

Andrew Godwin

unread,
Dec 14, 2011, 2:58:09 PM12/14/11
to south...@googlegroups.com
On 14/12/11 19:53, David Spector wrote:
> Hi
>
> Am trying to create a migration that replaces a couple of datetime
> fields using a new abstract class, but when I try to have south set up
> the schema migration I get a crash because south doesn't seem to know
> about the datetime module. Any ideas on how to get around this?
>
> tia,
> David
>
> here's the trace:
>
> %python manage.py schemamigration --auto schoolinfo
> extended_model_timestamps
> ? The field 'CourseInstance.modified_at' does not have a default
> specified, yet is NOT NULL.
> ? Since you are removing this field, you MUST specify a default
> ? value to use for existing rows. Would you like to:
> ? 1. Quit now, and add a default to the field in models.py
> ? 2. Specify a one-off value to use for existing columns now
> ? 3. Disable the backwards migration by raising an exception.
> ? Please select a choice: 2
> ? Please enter Python code for your one-off default value.
> ? The datetime module is available, so you can do e.g.
> datetime.date.today()
> >>> datetime.date.utcnow()

That's because datetime.date.utcnow() doesn't exist. You want either
datetime.datetime.utcnow(), or datetime.date.today().

Andrew

David Spector

unread,
Dec 14, 2011, 3:06:39 PM12/14/11
to South Users
doh! Thank you.

(someone might want to fix the docs so it uses
datetime.datetime.utcnow() in the help text's example! :)

Reply all
Reply to author
Forward
0 new messages