On Fri, Jan 2, 2009 at 12:57 PM, hotani <hot...@gmail.com> wrote:

>
> I have 3 fields that need to be unique together: office, county and
> case_no. In the "Case" model, I have the following:
>
> --
> class Case(models.Model):
>  office = models.ForeignKey(Office, editable=False)
>  county = models.ForeignKey(County)
>  case_no = models.CharField(max_length=20)
>  ...
>
>  class Meta:
>    unique_together = ("office", "county", "case_no")
>
> --
>
> Using forms, when I try to submit a duplicate I get a nasty 500 error:
> "duplicate key violates unique constraint..." rather than a form
> error.
>
> This is a new constraint I added to the database and am trying to get
> django to recognize it.
>

Given what you have specified, Django form validation will be checking to
ensure that the combo of office, county, and case_no is unique in the
database.  Since you aren't getting a form error, apparently this unique
check is passing.  You are instead getting a database level error (uncaught
leading to the 500 error), meaning mostly lieley that the constraint you
have placed in the DB differs somehow from what you have specified to
Django.  What exactly does the database error say?  You left out the most
important part for determining how what Django is checking differs from what
the database is enforcing.

If it seems they are the same, then ensure you are running 1.0.2 (there were
some fixes made to unique checking between 1.0 and 1.0.2).  If that doesn't
fix it, possibly you have hit a bug, but exact details of what you are
getting from the DB would really help in tracking down what is going wrong.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to