Django Unittest无法使用TypeError运行:isinstance()arg 2必须是一台机器上的类型或元组,而不是其他机器上的类型或元组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django Unittest无法使用TypeError运行:isinstance()arg 2必须是一台机器上的类型或元组,而不是其他机器上的类型或元组相关的知识,希望对你有一定的参考价值。
出于某种原因,我无法在我的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:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagement\__init__.py", line 381, in execute_from_command_line utility.execute() File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagement\__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementcommands est.py", line 26, in run_from_argv super().run_from_argv(argv) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementase.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementase.py", line 353, in execute output = self.handle(*args, **options) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementcommands est.py", line 56, in handle failures = test_runner.run_tests(test_labels) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjango est unner.py", line 604, in run_tests old_config = self.setup_databases() File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjango est unner.py", line 551, in setup_databases self.parallel, **kwargs File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjango estutils.py", line 174, in setup_databases serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True), File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbackendsasecreation.py", line 68, in create_test_db run_syncdb=True, File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagement\__init__.py", line 148, in call_command return command.execute(*args, **defaults) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementase.py", line 353, in execute output = self.handle(*args, **options) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementase.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangocoremanagementcommandsmigrate.py", line 203, in handle fake_initial=fake_initial, File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbmigrationsexecutor.py", line 117, in migrate state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbmigrationsexecutor.py", line 147, in _migrate_all_forwards state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbmigrationsexecutor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbmigrationsmigration.py", line 124, in apply operation.database_forwards(self.app_label, schema_editor, old_state, project_state) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbmigrationsoperationsfields.py", line 84, in database_forwards field, File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbackendssqlite3schema.py", line 309, in add_field self._remake_table(model, create_field=field) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbackendssqlite3schema.py", line 181, in _remake_table self.effective_default(create_field) File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbackendsaseschema.py", line 218, in effective_default default = field.get_default() File "C:UserspersonAAppDataLocalProgramsPythonPython36-32libsite-packagesdjangodbmodelsfields elated.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的一部分。
答案
如何在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)):
以上是关于Django Unittest无法使用TypeError运行:isinstance()arg 2必须是一台机器上的类型或元组,而不是其他机器上的类型或元组的主要内容,如果未能解决你的问题,请参考以下文章