Django Unittest无法通过TypeError运行:isinstance()arg 2必须是一台计算机上的类型或类型元组,而不能是其他计算机上的类型或元组

时间:2019-01-12 01:54:38

标签: django python-3.x

由于某种原因,我无法在Windows机器上运行“ manage.py test AppNameHere”,但是当我在Linux机器上运行它(我不确定操作系统在这里是否真的很重要)时,测试运行良好。我收到此错误:

2019-01-11 17:35:32 [DEBUG] faker.factory: Not in REPL -> leaving logger event level as is.
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 22, in 
    execute_from_command_line(sys.argv)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\test.py", line 26, in run_from_argv
    super().run_from_argv(argv)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\test.py", line 56, in handle
    failures = test_runner.run_tests(test_labels)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\test\runner.py", line 604, in run_tests
    old_config = self.setup_databases()
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\test\runner.py", line 551, in setup_databases
    self.parallel, **kwargs
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\test\utils.py", line 174, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\base\creation.py", line 68, in create_test_db
    run_syncdb=True,
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 148, in call_command
    return command.execute(*args, **defaults)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
    field,
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 309, in add_field
    self._remake_table(model, create_field=field)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 181, in _remake_table
    self.effective_default(create_field)
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\base\schema.py", line 218, in effective_default
    default = field.get_default()
  File "C:\Users\personA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\fields\related.py", line 927, in get_default
    if isinstance(field_default, self.remote_field.model):
TypeError: isinstance() arg 2 must be a type or tuple of types

这看起来像是Django出了点问题,但我不确定。有人对此有任何见解吗?我不想修改跟踪中的任何文件,因为它们是Django的一部分。

2 个答案:

答案 0 :(得分:0)

如何更改代码 get_default中的文件“ C:\ Users \ personA \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ django \ db \ models \ fields \ related.py”,第927行

如果isinstance(field_default,type(self.remote_field.model)):

答案 1 :(得分:0)

我通过以下方式解决了这个问题:

  • 删除我的所有迁移文件
  • 删除django_migrations表中的条目
  • 重新制作的迁移(makemigrations)
  • 进行了迁移--fake