M
M
matveyvarg2016-05-05 10:08:49
Django
matveyvarg, 2016-05-05 10:08:49

Why is the _id may not be null error thrown?

I want to make a rating, and for this I added the voted_by field to keep track of those who voted. The migrations went fine, but an exception is thrown: base_record.voted_by_id may not be NULL .
Model:

class Record(models.Model):

  title = models.CharField(max_length=128)
  author = models.ForeignKey(UserProfile,related_name='record')
  voted_by = models.ForeignKey(UserProfile,related_name='voted_by',blank=True)
  description = models.CharField(max_length=128)
  duration = models.IntegerField(default=0)
  likes = models.IntegerField(default=0)
  rating = models.FloatField(default=0)
  price = models.DecimalField(max_digits=10,decimal_places=2,default=0)
  file = models.FileField()
  def __unicode__(self):
    return self.title

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-05-05
@matveyvarg

When is it thrown out? It would be nice to see the entire stack trace. I suspect that instead of blank=True in the parameters of the voted_by field, you should write null=True.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question