You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django后端执行makemigrations报错:NameError: name 'Include' is not defined

Django执行makemigrations报错:NameError: name 'Include' is not defined

问题详情

  • 使用环境:Python 3.9,基于Django开发移动端后端应用
  • 执行命令:python manage.py makemigrations
  • 报错信息:
Traceback (most recent call last):
  File "/Users/neddy-glenatege/PycharmProjects/pythonProject/pythonProject/SchoolApp/APISchool/manage.py", line 22, in <module>
    main()
  File "/Users/neddy-glenatege/PycharmProjects/pythonProject/pythonProject/SchoolApp/APISchool/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/management/base.py", line 453, in execute
    self.check()
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/management/base.py", line 485, in check
    all_issues = checks.run_checks(
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    return check_method()
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/urls/resolvers.py", line 494, in check
    for pattern in self.url_patterns:
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/urls/resolvers.py", line 715, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/utils/functional.py", line 57, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/neddy-glenatege/Library/Python/3.9/lib/python/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
    return import_module(self.urlconf_name)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/neddy-glenatege/PycharmProjects/pythonProject/pythonProject/SchoolApp/APISchool/APISchool/urls.py", line 8, in <module>
    path('', Include('api.urls')),
NameError: name 'Include' is not defined
  • 预期执行结果:
Migration for "school":
   school\migration\0001_initial.py
   - Create model Article

解决方案

问题根源是URL配置文件的大小写错误和导入缺失,按以下步骤修正:

  1. 完善导入语句:打开/Users/neddy-glenatege/PycharmProjects/pythonProject/pythonProject/SchoolApp/APISchool/APISchool/urls.py,确保顶部导入小写的include:
from django.urls import path, include
  1. 修正路径代码:将文件第8行的Include改为小写的include:
path('', include('api.urls')),
  1. 保存文件后,重新执行命令:
python manage.py makemigrations

内容的提问来源于stack exchange,提问作者Neddy Glen Jean Baptist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 05:02:10