django3执行迁移出现:django.core.exceptions.ImproperlyConfigured: Cannot import
django3执行数据库迁移时出现如下错误:
Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/django/apps/config.py", line 244, in create app_module = import_module(app_name) File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1014, in _gcd_import File " ", line 991, in _find_and_load File " ", line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named 'students' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 22, in main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.8/dist-packages/django/core/management/__init__.py", line 395, in execute django.setup() File "/usr/local/lib/python3.8/dist-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) File "/usr/local/lib/python3.8/dist-packages/django/apps/config.py", line 246, in create raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Cannot import 'students'. Check that 'apps.students.apps.studentsConfig.name' is correct.
出现原因:因为students这个被创建在apps的文件夹里
apps.py文件内容
from django.apps import AppConfig class StudentsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'students'
解决办法:将name = 'students',改成name = 'apps.students'
from django.apps import AppConfig class StudentsConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'apps.students'
然后再执行,python3 manage.py makemigrates