Thursday, May 25, 2017

Re: null value in column violates not-null constraint

Thanks for answering man!

On Thursday, May 25, 2017 at 11:44:08 PM UTC+2, Melvyn Sopacua wrote:

Let me spell it out:

If the error message complains about the user field

And the code you provided is correct

Then your database is out of sync with your model definition

 

 

On Thursday 25 May 2017 13:53:19 Ismail Sarenkapic wrote:

> Tnx ,

> I know that i can manually select the user, but i want it to be

> automatic-with current user to add the product

>

> > > class Product(models.Model):

> > > seller = models.ForeignKey(settings.AUTH_USER_MODEL)

^^^^^^^^^ Here is the seller field

 

> > >

> > > #user = models.OneToOneField(settings.AUTH_USER_MODEL)

^^^^^^^ There is no user field. form.instance.user = 'foo' does not translate to anything useful.

The FormUserNeededMixin sets Product.user, which simply adds an instance variable, that is not picked up by the ORM, because 'user' is not a field in Product.fields.

 

The error should actually be about a field called 'seller', but because it is not in the form, it is not passed to the ORM and the old table complains about the user field, as it is the one that it still has.

 

--

Melvyn Sopacua

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7a5e9188-4b9a-4f4b-802f-3683cdd7e127%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment