Thursday, July 30, 2020

IntegrityError: null value in column "user_id" violates not-null constraint

I'm trying to save image in postgres database. I have upload model which has a foreign key reference to the extended custom user model. But it shows the following error


uploads/model.py
from django.db import models
from django.contrib.auth import get_user_model

User = get_user_model()

class Upload(models.Model):
    upload_file
= models.ImageField(upload_to='uploads/')
    upload_date
= models.DateTimeField(auto_now_add =True)
    user
= models.ForeignKey(User, on_delete=models.CASCADE)


What am I missing? Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bddd1f92-895c-4e23-8f08-976c0f178f17o%40googlegroups.com.

No comments:

Post a Comment