python - 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
谢谢!
解决方案
这对我有用。在名称中使用相同的大小写。
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
...
]
推荐阅读
- amazon-web-services - 命名数千个实例有哪些好的做法?
- python - 如何有条件地跳过不包含 pd.read_html() 中的表的 html 文件?
- php - 在 WooCommerce order_date 中添加 4 个工作日
- python - 将首字母缩略词与其长形式匹配
- java - 如何在消息到达 mqtt 时获取订阅的主题?
- typescript - 类型错误 web crypto importKey 算法参数
- objective-c - 适用于 macOS 的 AirPlay API
- php - 如何修复意外变量?(T_VAR)
- jquery - 如何防止 html 附加到跨度;当(div)计数的总数为零时?
- javascript - JS同步未按顺序触发