(1054,“字段列表中的未知列'日期'”)

时间:2014-12-20 16:47:00

标签: python mysql django django-models

日期字段存在于模型和数据库中,但仍显示错误为“(1054,”字段列表中的“未知列'日期'”)“我知道错误在哪里

form.py

from django import forms
from .models import feed

class feed_form(forms.ModelForm):
    class Meta:
        model = feed
        fields = ('feed_text',  )

views.py

def upload(request):
    form = feed_form(data=request.POST)
    feed_cont = form.save(commit=False)
    feed_cont.user = User.objects.get(pk =1)
    feed_cont.upvote = 0
    feed_cont.downvote = 0
    feed_cont.date = "hello"
    feed_cont.save()
    return render(request,'feeds/feeds.html')

models.py

class feed(models.Model):
    user = models.ForeignKey(User,null=True,blank=True)
    feed_text = models.CharField(max_length=2000)
    date = models.CharField(max_length=30)
    upvote = models.IntegerField(default=0)
    downvote = models.IntegerField(default=0)

    def __str__(self):
        return feed.content

为什么会出现这个错误? 提前致谢

1 个答案:

答案 0 :(得分:0)

Yoy在您的模型中有date列,但您在数据库中存储的表中没有此列。您应该创建该列(手动或使用migrations),因为syncdb不会创建它。