推荐系统中的非空约束失败错误

时间:2017-07-10 09:12:27

标签: django python-3.x

我尝试在我的项目的评论页面中添加图片。图片已更新,但我收到错误

sqlite3.IntegrityError:NOT NULL约束失败:reviews_review.pub_date

我的models.py看起来像这样:

class Review(models.Model):
    RATING_CHOICES = (
        (1, '1'),
        (2, '2'),
        (3, '3'),
        (4, '4'),
        (5, '5'),
    )
    wine = models.ForeignKey(Wine)
    pub_date = models.DateTimeField('date published')
    user_name = models.CharField(max_length=100)
    comment = models.CharField(max_length=200)
    rating = models.IntegerField(choices=RATING_CHOICES)
    images = models.ImageField(null = True, blank=True)

reviews_list的代码如下所示:

{% extends 'base.html' %}

{% block title %}
<h2>Latest reviews</h2>
{% load static %}
{% endblock %}

{% block content %}
{% if latest_review_list %}
<div class="row">
    {% for review in latest_review_list %}
    <div class="col-xs-6 col-lg-4">




        <h4><a href="{% url 'reviews:review_detail' review.id %}">
        {{ review.wine.name }}

        </a></h4>
 <br>
        <a><img src="{% static wine.images.url %}" height="200"></a>     


        <h6>rated {{ review.rating }} of 5 by <a href="{% url 'reviews:user_review_list' review.user_name %}" >{{ review.user_name }}</a></h6>
        <p>{{ review.comment }}</p>
    </div>
    {% endfor %}
</div>
{% else %}
<p>No reviews are available.</p>
{% endif %}
{% endblock %}

1 个答案:

答案 0 :(得分:1)

当您保存对象时,pub_date = models.DateTimeField('date published', null=True) 没有值。所以你可以做的一件事是

makemigrations

然后执行migratepilot