Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

django

Hi I am getting this error because I have a field in my additional user info model (user = models.OneToOneField(User)) that I am not filling in at sign up (as I want to let the user do it later).

I wondered if there was any way to solve this problem other than allowing null field in the db?

Cheers

like image 874
weaveoftheride Avatar asked May 26 '26 05:05

weaveoftheride


2 Answers

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

like image 153
Sergei Avatar answered May 27 '26 19:05

Sergei


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):)

like image 26
DragonFire Avatar answered May 27 '26 17:05

DragonFire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!