Skip to content Skip to sidebar Skip to footer

Django IntegrityError: Null Value In Column "interestreceiver_id" Of Relation "HomeFeed_interest" Violates Not-null Constraint

Django : Why is my submit interest form not submitted because of an integrity error issue? Did I write my view or template wrongly? How should I solve this error as i've never enco

Solution 1:

This error is saying : in you database there is a null value stored whole the column have not null constraint

Quick fix: Add to the field causing the error. blank=True, null=True

When null is not an option in interestreceiver then you will have to manually remove the null values from the database!

You can do that by running this command

Python manage.py dbshell

EDIT:

Please check that you do not have null values in the database. Null values can be generated automatically if you created new fields. If you adding the field recently then you will have to pass Null= True, no other way. Then you make the blog post view only for authenticated users.

When this error come up when you submit the blog then, you are somehow passing a null value for the intrestreceiver here:

 # add this line before intrest_request to make sure you are not passing Null value
  print(blog_post.author, user)
  interest_requests = Interest.objects.filter(interestsender=user, 
                    interestreceiver=blog_post.author, is_active=True)

and see if the value is coming throw.

when the value is coming through and you are still getting the error then I do not know how did you structure your database, review related_field documentation on here: https://docs.djangoproject.com/en/3.1/topics/db/queries/#backwards-related-objects


Post a Comment for "Django IntegrityError: Null Value In Column "interestreceiver_id" Of Relation "HomeFeed_interest" Violates Not-null Constraint"