﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11978	'Duplicate key value violates unique constraint' error while changing inline admin model	kozlenko	nobody	"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."	Uncategorized	closed	Forms	1.1	Normal	invalid			Unreviewed	0	0	0	0	0	0
