Friday, July 31, 2020

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

You will need to login into the database admin page ( maybe pgadmin ) to update the user_id . From your model, user_id  can't be null 
AJAYI Sunday 
(+234) 806 771 5394



On Thu, Jul 30, 2020 at 11:58 AM Dinolin yp job <dinolinypjob@gmail.com> wrote:


It worked but the user_id in uploads_upload is empty. How can I can make that work?
On Thursday, July 30, 2020 at 3:31:21 PM UTC+5:30 obast...@gmail.com wrote:
From the error, it states that you are trying to add an upload object to the database without a user. And from your model.py, the User foreign key does not have a null=True, and blank=True. So you can't save a null value for that user field. 

On Thu, Jul 30, 2020 at 10:52 AM Dinolin yp job <dinoli...@gmail.com> wrote:
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...@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.

--
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/57100db3-81b7-49ca-86e6-096c121c94c8n%40googlegroups.com.

--
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/CAKYSAw0noinV2U%2BBCYCEc_dSbYxY7RFLwyrKKpxQWqy%2BfuW%2BNA%40mail.gmail.com.

No comments:

Post a Comment