Django数据库迁移跟踪(最近调用最后一次):

tquggr8v  于 2023-05-01  发布在  Go
关注(0)|答案(1)|浏览(124)

我是Django Python的初学者。在创建表并运行迁移命令后,我得到了下面附加的错误。到目前为止我尝试过的东西我附在下面。

models.py

from django.db import models

# Create your models here.

class Students(models.Model):
    StudentId = models.AutoField(primary_key=True)
    StudentName = models.CharField(max_length=500)
    Course = models.CharField(max_length=500)
    Fee =models.CharField(max_length=500)

运行迁移命令后完全错误:pythonwww.example. www.example.com makemigrations StudentApp

Traceback (most recent call last):

  File "E:\django\stud_crud\manage.py", line 22, in <module>
    main()
  File "E:\django\stud_crud\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\core\management\__init__.py", line 416, in execute
    django.setup()
  File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
                 ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\apps\config.py", line 178, in create
    mod = import_module(mod_path)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Hp\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'StudentApp'

enter image description here

ufj5ltwl

ufj5ltwl1#

请检查两件事:

**首先:**检查您的文件夹结构。我看到了你的结构的图像,但不能判断,因为我不熟悉那个IDE。您的文件夹结构应该像这样设置:

STUD_CRUD/ -stud_crud/
           -students/
           -manage.py

**第二步:**检查应用的命名。它应该看起来像这样:

# settings.py
INSTALLED_APPS = [
    # [...]
    "students.apps.StudentsConfig",
]

这里的“第一个”学生指的是您为应用指定的文件夹名称。所以students是正确的;我用你的项目的图像进行了验证。StudentsConfig是指您在www. example中给出的类名 www.example.com 学生文件夹.

# apps.py
from django.apps import AppConfig
class StudentsConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "students"

在某个地方你有其他变量名。我举了一个应该起作用的例子。
我几乎可以肯定你的错误是在STUD_CRUD/students/apps.py中找到的。

相关问题