#11978 closed Uncategorized (invalid)
'Duplicate key value violates unique constraint' error while changing inline admin model
Reported by: | kozlenko | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi.
I have a DB error 'Duplicate key value violates unique constraint' while changing model from admin inline form.
The model 'Primary' related to the 'Secondary' as one-to-one via OneToOneField.
When i'm trying to change the data of 'Secondary' on 'Primary' admin change page, after for mubmission raising error 'current transaction is aborted, commands ignored until end of transaction block'. It's logically that previous query returned error and this error is: 'Duplicate key value violates unique constraint "project_secondary_primary_id_key"'.
Here is the source:
models.py
class Primary(models.Model): choice_limits = {'groups__name': 'clients', 'is_staff': False} user = models.ForeignKey(User) additional = models.ManyToManyField(Additional) class Secondary(models.Model): id = models.CharField(max_length = 64, primary_key = True, unique = True) file = models.FileField(upload_to=upload_callback, max_length=256) upload_date = models.DateField(auto_now_add=True) second = models.OneToOneField(Purchase)
admin.py
class PrimaryAdmin(admin.ModelAdmin): """ methods here """ """ some definitions here """ inlines = [SecondaryInline] class SecondaryAdmin(admin.ModelAdmin): """ methods here """ """ some definitions here """ admin.site.register(Primary, PrimaryAdmin) admin.site.register(Secondary, SecondaryAdmin)
I've already tried to write Forms and Formsets, but that didn't helped.
Thanks for response.
Change History (3)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Issue resolved. Problem was in internal Secondary exception.
It catch quietly but breaks form submission.
comment:3 by , 11 years ago
Easy pickings: | unset |
---|---|
Severity: | → Normal |
Type: | → Uncategorized |
UI/UX: | unset |
Can you please share your solution?
This error resolved by adding new int primary key - error was because of updating id field.
But it is new error now: