获取迁移错误

时间:2019-03-03 01:42:28

标签: python django-models django-migrations

我遇到迁移错误。我尝试删除以前的迁移。错误告诉它无法写入/创建迁移文件,错误如下。

Traceback (most recent call last):
 File "manage.py", line 15, in <module>
 execute_from_command_line(sys.argv)
 File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages         /django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
 File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
 self.execute(*args, **cmd_options)
 File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
  output = self.handle(*args, **options)
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
  res = handle_func(*args, **kwargs)
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 184, in handle
  self.write_migration_files(changes)
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/core/management/commands/makemigrations.py", line 222, in  write_migration_files
   migration_string = writer.as_string()
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/writer.py", line 151, in as_string
    operation_string, operation_imports = OperationWriter(operation).serialize()
   File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/writer.py", line 110, in serialize
_write(arg_name, arg_value)
 File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/writer.py", line 62, in _write
arg_string, arg_imports = MigrationWriter.serialize(item)
 File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/writer.py", line 279, in serialize
  return serializer_factory(value).serialize()
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/serializer.py", line 37, in serialize
  item_string, item_imports = serializer_factory(item).serialize()
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/serializer.py", line 197, in serialize
  return self.serialize_deconstructed(path, args, kwargs)
  File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/serializer.py", line 85, in serialize_deconstructed
arg_string, arg_imports = serializer_factory(arg).serialize()
File "/home/clifton/Documents/all_venvs/unica/lib/python3.6/site-packages/django/db/migrations/serializer.py", line 149, in serialize
raise ValueError("Cannot serialize function %r: No module" % self.value)
 ValueError: Cannot serialize function <built-in method time of datetime.datetime object at 0x7f1ec51abb40>: No module

1 个答案:

答案 0 :(得分:1)

在自定义字段定义中使用时间存在问题。

这很难发现,因为它没有在追溯中列出,并且使用该自定义字段的特定模型也不会引发错误。

但是,尝试在模型的“时间”字段中添加auto_now_add=True