I have created two new fields on my model. Created and updated. They are both DateTimeField objects. When I run makemigrations it asks for a fix because there is no default value for the two fields. I have tried datetime.now(), datetime.datetime.now(), datetime.date.today(), etc. However, I keep getting the same error so I can't update my tables. Here is the error I am getting:
-- You are trying to add a non-nullable field 'created' to chore without a default;
we can not 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)
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 module is available, so you can do e.g. datetime.date.today()
>>> datetime.datetime.now
Traceback (most recent call last):
File "/Applications/PyCharm.app/helpers/pycharm/django_manage.py", line 23, in <module>
run_module(manage_file, None, '__main__', True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "...manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "...lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "...lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "...lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "...lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
output = self.handle(*args, **options)
File "...lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 111, in handle
convert_apps=app_labels or None,
File "...lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 50, in changes
changes = self._detect_changes(convert_apps, graph)
File "...lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 180, in _detect_changes
self.generate_added_fields()
File "...lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 720, in generate_added_fields
field.default = self.questioner.ask_not_null_addition(field_name, model_name)
File "...lib/python2.7/site-packages/django/db/migrations/questioner.py", line 119, in ask_not_null_addition
code = input(">>> ").decode(sys.stdin.encoding)
TypeError: decode() argument 1 must be string, not None
Any ideas how to make this work?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c456ac80-36ff-41d0-bc8a-df98554cc403%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment