python - Foreign Key Integrity error in Django 1.7 -
I have a project where a user can review the service whenever I review with the same user twice I try to write, I get a complete error:
Duplicate key value violates unique restriction "reviews_review_user_id_key" Description: Key (user_id) = (7) already exists. I am sure why I got this error, is it because there are many relationships between users and reviews?
The review model looks like this:
Category review (models.Model): User = models.ForeignKey (user) service = models.ForeignKey ('services. Service ') rating_value = model.tegetfilled (default = 0) review_text = models.CharField (max_length = 500, default = "null") pub_date = model datetimefilled (default = timezone.nough, empty = true) def __str __ (self) : Python2 returns self_service_name at # __unicode__
It appears that you have models Removed unique obstacle in .py, but databay A unique obstacle on coordination is still present. It happened before me and I was able to overcome the compulsion through the table. /manage.py dbshell and everything worked as expected.
Not sure which DB you are using, but for PostGrace: ALTER TABLE your_table DROP CONSTRAINT reviews_review_user_id_key;
Give it a shot, hope it helps.
Comments
Post a Comment