Hello,

Because your implementation is wrong.

Please read this https://tech.serhatteker.com/post/2020-01/uuid-primary-key/

Jason <jjohns98...@gmail.com> schrieb am So., 6. Feb. 2022, 00:27:

> A bit of a hint about your db schema, do you want a user ID to be one to
> one with each book plot?  also, why is your primary key a string field?
> On Saturday, February 5, 2022 at 10:43:05 AM UTC-5 armaan...@gmail.com
> wrote:
>
>> Hello everyone,
>>
>> when i am trying to add uuid primary key , I am getting this error UNIQUE
>> constraint failed: matrixapp_bookplot.user_id
>>
>> what is wrong here
>>
>> class BookPlot(models.Model):
>>
>>         ref_id = models.CharField(max_length=25)
>>         code = str(uuid.uuid4()).replace("-", "")[:4]
>>         user_id=models.CharField(primary_key=True,max_length=50,
>> default=code, editable=False)
>>         plot_number = models.CharField(max_length=25)
>>         Payable_amout = models.IntegerField(null=True, blank=True)
>>         Mnthly_Installment = models.IntegerField(null=True, blank=True)
>>         number_of_Installment = models.IntegerField()
>>         name = models.CharField(max_length=100)
>>         father_name = models.CharField(max_length=100)
>>         mobile_no = models.IntegerField()
>>         payment_mode = models.CharField(max_length=10)
>>         remarks = models.CharField(max_length=100)
>>         receipt = models.ImageField(upload_to = 'receipt/', null= True,
>> blank=True)
>>
>> joinig_date=models.DateField(auto_now_add=True,null=True,blank=True)
>>
>>
>>
>>
>>     def  bookplot(request):
>>
>>
>>         if request.method =="POST":
>>             ref_id = request.POST.get('ref_id')
>>
>>             plot_number = request.POST.get('plot_number')
>>             amount = request.POST.get('amount')
>>             Mnthly_Installment = request.POST.get('Mnthly_installment')
>>             no_Installment = request.POST.get('no_Installment')
>>             name = request.POST.get('name')
>>             father_name = request.POST.get('father_name')
>>             mobile_number = request.POST.get('mobile_number')
>>             payment_mode = request.POST.get('payment_mode')
>>             remarks = request.POST.get('remarks')
>>             receipt = request.FILES.get('receipt')
>>             print(ref_id)
>>             book_plot = BookPlot(ref_id= ref_id,plot_number =
>> plot_number, Payable_amout = amount,Mnthly_Installment =
>> Mnthly_Installment, number_of_Installment = no_Installment, name =
>> name,father_name = father_name , mobile_no = mobile_number, payment_mode =
>> payment_mode ,remarks=remarks,receipt=receipt )
>>             book_plot.save()
>>
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8e0d1acf-a7c2-4a6b-9b04-001856d47071n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8e0d1acf-a7c2-4a6b-9b04-001856d47071n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9my2cwrWhGOty3H6Vn%3Du7xQqFh242m8YHV_vZ7QV9gBsiA%40mail.gmail.com.

Reply via email to