首页 > 解决方案 > Django makemigrations - 没有安装带有标签的应用程序''

问题描述

这里是 Django Web 框架的初学者......当我尝试运行 python manage.py makemigration 课程时,它会抛出这个错误:

$ python manage.py makemigrations courses
←[31;1mNo installed app with label 'courses'.

这是我在 INSTALLED_APPS 的 settings.py 中的内容

INSTALLED_APPS = [
    'courses.apps',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

这是在我的 apps.py 文件中:

from django.apps import AppConfig
class CoursesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'Courses'

这是 python manage.py showmigrations 给出的:

$ python manage.py showmigrations
←[1madmin
←[0m [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
 [X] 0003_logentry_add_action_flag_choices
←[1mauth
←[0m [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
 [X] 0010_alter_group_name_max_length
 [X] 0011_update_proxy_permissions
 [X] 0012_alter_user_first_name_max_length
←[1mcontenttypes
←[0m [X] 0001_initial
 [X] 0002_remove_content_type_name
←[1msessions
←[0m [X] 0001_initial

另外,为什么我的终端输出中有这些 '←[31;1m' 和 '←[0m' 符号?我正在使用 VSCode

谢谢!

标签: pythondjango

解决方案


这对我有用。在名称中使用相同的大小写。

from django.apps import AppConfig
class CoursesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'courses'  # Instead of 'Courses'

然后在你的 settings.py

INSTALLED_APPS = [
    ...
    'courses',  # or courses.apps.CoursesConfig
    ...
]

推荐阅读