Django Unittest无法使用TypeError运行:isinstance()arg 2必须是一台机器上的类型或元组,而不是其他机器上的类型或元组

问题描述 投票:1回答:1

出于某种原因,我无法在我的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的一部分。

django python-3.x
1个回答
0
投票

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

if isinstance(field_default,type(self.remote_field.model)):

© www.soinside.com 2019 - 2024. All rights reserved.