使用django编写项目时,引用自定义模块,在迁移时,提示找不到模块
代码如下
from django.db import models
import sys
from perceptor.teachers.models import Teachers
sys.path.append('I:\\jiayong\\perceptor\\teachers\\models.py')
运行结果及报错内容
(venv) I:\jiayong\perceptor>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "I:\jiayong\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "I:\jiayong\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "I:\jiayong\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "I:\jiayong\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "I:\jiayong\venv\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "I:\python3.7.7\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "I:\jiayong\perceptor\course\models.py", line 4, in <module>
from perceptor.teachers.models import Teachers
ModuleNotFoundError: No module named 'perceptor'
我的解答思路和尝试过的方法
尝试用sys更改路径,仍提示perceptor(文件名)找不到
尝试更改项目名,也提示perceptor(文件名)找不到
CTRL加左键点击perceptor可以找到相应的文件,点击Teachers可以找到对应的类
我想要达到的结果
可以正确迁移,生成数据库表