[Django]-IntegrityError at /***/ (1048, "Column '***' cannot be null") in python django

8👍

Try to

user = models.OneToOneField(User, null=True, blank=True)

And then recreate your db.
You can find more on https://docs.djangoproject.com/en/1.4/ref/models/fields/#null

Else you can use Proxy models:

class UserExtraInfo(User):
#here your extra fields

In this case you won`t need to create UserExtraInfo instance in same time with User.
Read more on https://docs.djangoproject.com/en/1.4/topics/db/models/#model-inheritance

👤Sergei

0👍

Integrity error occurred basically when you define some database field as not null and pass

the null or blank value

I am assuming you are storing the value in your database by django form

so in that case you can do like

if request.method == POST: # whatever the method

   get_form_obj = form.save(commit = False)

Don’t forget to make change in your model user field like (null = True,blank = True)

hope this will help

👤Nags

0👍

For me it was depth = 1 in serializers.py, just remove this part and the request goes through. Nested serializers were causing the problem because of this (in console it was showing NestedSerializer(read_only=True):)

Leave a comment