django异常解决办法

  Applying mycode.0002_auto_20190101_1624...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\management\
__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\management\
__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\management\
base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\management\
base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\core\management\
commands\migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\migrations\ex
ecutor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_i
nitial=fake_initial)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\migrations\ex
ecutor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_
initial)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\migrations\ex
ecutor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\migrations\mi
gration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, projec
t_state)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\migrations\op
erations\fields.py", line 215, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\backends\base
\schema.py", line 513, in alter_field
    old_db_params, new_db_params, strict)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\backends\base
\schema.py", line 602, in _alter_field
    old_default = self.effective_default(old_field)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\backends\base
\schema.py", line 228, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\models\fields
\__init__.py", line 766, in get_db_prep_save
    prepared=False)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\models\fields
\__init__.py", line 758, in get_db_prep_value
    value = self.get_prep_value(value)
  File "G:\virtualenv\baiduwangpan\env\lib\site-packages\django\db\models\fields
\__init__.py", line 1849, in get_prep_value
    return int(value)

TypeError: int() argument must be a string or a number, not 'datetime.datetime'


Instead of models.DateTimeField(default = timezone.now) try models.DateTimeField(auto_now_add=True)



上一篇:利用阿里云函数计算做一些好玩的事情-案例实战
下一篇:阿里云代金券礼包升级到1888元