【问题标题】:django makemigrations nomodule found errordjango makemigrations nomodule 发现错误
【发布时间】:2022-01-03 22:36:07
【问题描述】:

我正在尝试添加模型,但每当我运行 python manage.py makemigrations 时,我都会收到以下错误

ModuleNotFoundError: No module named 'django.contrib.staticfilesaccounts'

accounts是我项目中的一个app,文件结构如下 file structure

模型文件是,

from django.db import models

    # Create your models here.
    
    class Customer(models.Model):
        name=models.CharField(max_length=200, null=True)
        phone=models.CharField(max_length=10, null=True)
        email=models.EmailField(max_length=20, null=True)
        dateCreated=models.DateField(auto_now_add=True)
    
        def __str__(self):
            return self.name
    
    class Product(models.Model):
        name=models.CharField(max_length=30, null=True)
        category=models.CharField(max_length=20, null=True)
        price=models.IntegerField(null=True)
    
        def __str__(self):
            return self.name

我是 Django 初学者,需要一些帮助。非常感谢

【问题讨论】:

    标签: django django-models makemigrations


    【解决方案1】:

    settings.py文件中的INSTALLED_APPS有错别字,应该是这样的:

    INSTALLED_APPS = [
        # ...
        'django.contrib.staticfiles',
        'accounts',
        #...
    ]
    

    【讨论】:

    • 是的 INSTALLED_APPS 包含 'django.contrib.staticfiles' 但我不明白为什么 django 正在寻找 'django.contrib.staticfilesaccounts'
    • 确保'django.contrib.staticfiles' app后面有逗号。
    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 2016-08-09
    • 1970-01-01
    • 2021-07-06
    • 2016-05-22
    • 2019-09-10
    • 2017-01-13
    • 2020-10-01
    相关资源
    最近更新 更多