由于某种原因,我无法manage.py在Windows机器上运行“www.example.com 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的一部分。
3条答案
按热度按时间flmtquvp1#
我通过以下方法解决了这个问题:
kiz8lqtg2#
更改get_default中的代码文件“C:\用户\个人A\应用数据\本地\程序\Python\Python 36 -32\lib\站点包\django\db\模型\字段\相关. py”的第927行怎么样
如果是示例(字段默认值,请键入(self.remote_field.model)):
qf9go6mv3#
此问题的另一个主要原因是定义或分配了不存在的
OneToOneField
或ForeignkeyField
。只需在模型示例中确认是否所有关系都具有现有模型