python 2.7 - DateTimeField migration error in django -


previously models' datetimefield initiated like

order_date = models.datetimefield(default=datetime.today) 

which throwing

typeerror: required argument 'year' (pos 1) not found 

when tried instantiate blank object. fixed datetime.datetime.now(). when try migrate shows same error

typeerror: required argument 'year' (pos 1) not found 

when make clean migration in fresh db not having problem. dont want go on route of making fresh db since don't have permissions in production. there way fix this?

traceback:

  running migrations:   rendering model states... done   applying xyz.0016_auto_20170728_0758...traceback (most recent call last):   file "manage.py", line 9, in <module>     execute_from_command_line(sys.argv)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line     utility.execute()   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv     self.execute(*args, **cmd_options)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute     output = self.handle(*args, **options)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle     executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate     self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/migrations/executor.py", line 147, in apply_migration     state = migration.apply(state, schema_editor)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply     operation.database_forwards(self.app_label, schema_editor, old_state, project_state)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards     schema_editor.alter_field(from_model, from_field, to_field)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 484, in alter_field     old_db_params, new_db_params, strict)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 567, in _alter_field     old_default = self.effective_default(old_field)   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 194, in effective_default     default = field.get_default()   file "/users/sayok/projects/invenv1/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 794, in get_default     return self.default() typeerror: required argument 'year' (pos 1) not found 

migration file

# -*- coding: utf-8 -*- __future__ import unicode_literals  django.db import models, migrations import datetime   class migration(migrations.migration):     dependencies = [         ('p1', '0015_vgvjvvhvvj'),     ]      operations = [         migrations.alterfield(             model_name='analyze',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 909746)),         ),         migrations.alterfield(             model_name='apiplaceorder',             name='order_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 972820)),         ),         migrations.alterfield(             model_name='hjjghjg',             name='order_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 980004)),         ),         migrations.alterfield(             model_name='banner',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 932895)),         ),         migrations.alterfield(             model_name='clusterarticle',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 975352)),         ),         migrations.alterfield(             model_name='clusterlog',             name='updated_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 885144)),         ),         migrations.alterfield(             model_name='customize',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 906463)),         ),         migrations.alterfield(             model_name='faqtopic',             name='created_date',          migrations.alterfield(             model_name='greetingstouser',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 963740)),         ),         migrations.alterfield(             model_name='kycsendemailtouser',             name='send_date',             field=models.datefield(default=datetime.date(2017, 7, 28)),         ),         migrations.alterfield(             model_name='liveorder',             name='order_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 971116)),         ),         migrations.alterfield(             model_name='hgjgjgjgjg',             name='last_login',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 976968)),         ),         migrations.alterfield(             model_name='newsletter',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 940914)),         ),         migrations.alterfield(             model_name='newslettertouser',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 942440)),         ),         migrations.alterfield(             model_name='newsroom',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 944774)),         ),         migrations.alterfield(             model_name='optimize',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 910911)),         ),         migrations.alterfield(             model_name='order',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 910911)),         ),         migrations.alterfield(             model_name='order',             name='order_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 913976)),         ),         migrations.alterfield(             model_name='orderaccountgraph',             name='order_date',             field=models.datefield(default=datetime.date(2017, 7, 28)),         ),         migrations.alterfield(             model_name='orderbuy',             name='order_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 918101)),         ),         migrations.alterfield(             model_name='orderhold',             name='hold_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 924012)),         ),         migrations.alterfield(             model_name='ordersell',             name='sell_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 921352)),         ),         migrations.alterfield(             model_name='ordertrack',             name='order_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 931269)),         ),         migrations.alterfield(             model_name='partner',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 904619)),         ),         migrations.alterfield(             model_name='recentlyviewedcluster',             name='viewed_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 911741)),         ),         migrations.alterfield(             model_name='seasongreetings',          migrations.alterfield(             model_name='seasongreetings',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 962918)),         ),         migrations.alterfield(             model_name='sitesetting',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 907550)),         ),         migrations.alterfield(             model_name='subscribe',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 940109)),         ),         migrations.alterfield(             model_name='team',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 905406)),         ),         migrations.alterfield(             model_name='testimonial',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 903870)),         ),         migrations.alterfield(             model_name='user',             name='created_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 891457)),         ),         migrations.alterfield(             model_name='usernotification',             name='notification_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 912805)),         ),         migrations.alterfield(             model_name='vghgh',             name='application_date',             field=models.datetimefield(default=datetime.datetime(2017, 7, 28, 7, 58, 21, 957282)),         ),     ] 

this line in traceback suggests have incorrect default in previous migration.

old_default = self.effective_default(old_field) 

check old migrations in app, , default=datetime.datetime or default=datetime.date. these should default=datetime.datetime.today or datetime.date.today instead.

as aside, shouldn't use default=datetime.now(). django calling function when create migration, , freezing @ datetime(2017, 7, 28, 7, 58, 21). when run migration use datetime, if run many days now. use callable datetime.now instead.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -