AttributeError:'module'对象没有属性'Datefield'

Joh*_*Tan 3 python django

在models.py文件中

from django.db import models

# Create your models here.

class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

class Author(models.Model):
    first_name = models.CharField(max_length=30)
    last_name = models.CharField(max_length=40)
    email = models.EmailField()

class Books(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publishers = models.ForeignKey(Publisher)
    publication_date = models.Datefield()
Run Code Online (Sandbox Code Playgroud)

当我运行命令

$ python manage.py validate
Run Code Online (Sandbox Code Playgroud)

我收到错误消息

AttributeError: 'module' object has no attribute 'Datefield'
Run Code Online (Sandbox Code Playgroud)

请帮忙.

Sha*_*hin 10

它应该是models.DateField一个资本F.

所以你的Books模型应该是这样的:

class Books(models.Model):
    title = models.CharField(max_length=100)
    authors = models.ManyToManyField(Author)
    publishers = models.ForeignKey(Publisher)
    publication_date = models.DateField()  # <--- Typo was here
Run Code Online (Sandbox Code Playgroud)