Thursday, May 25, 2017

Re: null value in column violates not-null constraint

Tnx ,
I know that i can manually select the user, but i want it to be automatic-with current user to add the product

On Thursday, May 25, 2017 at 7:13:39 PM UTC+2, Melvyn Sopacua wrote:

On Thursday 25 May 2017 04:19:56 Ismail Sarenkapic wrote:

> Hi, I'm trying to create a digital marketplace site where users will

> be able to register and submit their products.

> I created the Product model and connected it with User with foreign

> key.Everything seems to be alright, but when I submit my product i

> get the following error:

>

> null value in column violates not-null constraint

> it looks like relation between product and user is not properly

> configured(regardless of my mixin that is suppose to handle it)

 

> class Product(models.Model):

> seller = models.ForeignKey(settings.AUTH_USER_MODEL)

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

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

> # managers = models.ManyToManyField(settings.AUTH_USER_MODEL,

> related_name="managers_products", blank=True) title =

> models.CharField(max_length=30)

> #owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd slug =

> models.SlugField(blank=True, unique=True)

> description = models.TextField()

> price = models.DecimalField(max_digits=100, decimal_places=2,

> default=9.99, null=True,) #100.00

 

 

> class ProductModelForm(forms.ModelForm):

> class Meta:

> model = Product

> fields = [

> "title",

> "description",

> "price",

> ]

 

seller is not in the model form and FormUserNeededMixin doesn't change that. The user field is commented out in your model so this error and the quoted code are not in sync.

 

But it could also be the slug. Without more of the error message it's hard to tell.

--

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/ddc8f477-7668-4694-8be8-867494022bf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment