{{{
class VoiceMessage(models.Model):
....
duration = models.DurationField(help_text='Contains the sample duration')
...
}}}
It's not a nullable field, so makemigrations correctly asks me for a
default value:
{{{
(env) bastb@bastb-vps:/var/www/brownpapersession/dev/brownpapersession$
python manage.py makemigrations
You are trying to add a non-nullable field 'duration' to voicemessage
without a default; we can't do that (the database needs something to
populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows with a
null value for this column)
2) Quit, and let me add a default in models.py
Select an option: 1
Please enter the default value now, as valid Python
The datetime and django.utils.timezone modules are available, so you can
do e.g. timezone.now
Type 'exit' to exit this prompt
>>> datetime.timedelta(seconds=1)
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/core/management/__init__.py", line 371, in
execute_from_command_line
utility.execute()
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/core/management/commands/makemigrations.py", line 159, in
handle
migration_name=self.migration_name,
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/db/migrations/autodetector.py", line 44, in changes
changes = self._detect_changes(convert_apps, graph)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/db/migrations/autodetector.py", line 183, in
_detect_changes
self.generate_added_fields()
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/db/migrations/autodetector.py", line 824, in
generate_added_fields
self._generate_added_field(app_label, model_name, field_name)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/db/migrations/autodetector.py", line 844, in
_generate_added_field
field.default = self.questioner.ask_not_null_addition(field_name,
model_name)
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/db/migrations/questioner.py", line 158, in
ask_not_null_addition
return self._ask_default()
File "/var/www/brownpapersession/dev/env/lib/python3.5/site-
packages/django/db/migrations/questioner.py", line 138, in _ask_default
return eval(code, {}, {"datetime": datetime_safe, "timezone":
timezone})
File "<string>", line 1, in <module>
AttributeError: module 'django.utils.datetime_safe' has no attribute
'timedelta'
}}}
To me, the informative message `The datetime and django.utils.timezone
modules are available, so you can do e.g. timezone.now` suggests that the
python `datetime` module is available, especially because the Django
`timezone` was displayed as `django.utils.timezone`.
I'm working around it by accepting a null and blank value for now. I'm
happy to create a PR if needed
--
Ticket URL: <https://code.djangoproject.com/ticket/29595>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Comment:
I guess it might be a matter of adding the `timedelta` import in
`django.utils.datetime_safe`.
--
Ticket URL: <https://code.djangoproject.com/ticket/29595#comment:1>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/10230 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29595#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"c72dde41e603093ab0bb12fa24fa69cfda0d35f9" c72dde41]:
{{{
#!CommitTicketReference repository=""
revision="c72dde41e603093ab0bb12fa24fa69cfda0d35f9"
Fixed #29595 -- Allowed using timedelta in migrations questioner.
Refs #29600 -- Removed usage of django.utils.datetime_safe in migrations.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29595#comment:3>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"44accb066a51d15f27e38f203c73830eddea16df" 44accb0]:
{{{
#!CommitTicketReference repository=""
revision="44accb066a51d15f27e38f203c73830eddea16df"
Refs #32738, Refs #29600, Refs #29595 -- Removed unused
django.utils.datetime_safe.time().
Unused since c72dde41e603093ab0bb12fa24fa69cfda0d35f9.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29595#comment:4>