Not seeing your table definition, the problem appears to be a data modeling
issue. The constraint says each ("sentence_id","start","end") combination is
unique, and the integrity exception is complaining that the data supplied is
not unique. The code snippet for the inserts does have duplicate data for
these 3 columns, so the exception seems to be correct.

The question is what should be unique?
("sentence_id","start","end") within something else? If so, the constraint
must include the columns for the something else.
If the constraint is right, then it looks like you are getting correct
behavior.

Posting your table definitions also would help.

-- 
Mike Conley



On Tue, Jul 7, 2009 at 12:12 PM, Nathan Harmston <
iwanttobeabad...@googlemail.com> wrote:

>
> Hi,
> Currently I have a mapper like this:
>
> class Entity:
>    def __init__(self, type, create, sentence_id, start, end):
>         self.type = type
>         self.create = create
>         self.sentence_id = sentence_id
>         self.start = start
>         self.end = end
>
> class Interval:
>    def __init__(self, sentence_id, start, end):
>         self.type = type
>         self.create = create
>         self.start = start
>         self.end = end
>
> mapper(Interval, intervals_table)
> mapper(Entity, entities_table.join(intervals_table,
> intervals_table.c.interval_id == entities_table.c.interval_id))
>
> However I have the problem that an interval is unique ( there is a
> UniqueConstraint("sentence_id", "start", "end") ). So when I create an
> Entity object like so
>   e = Entity("FOO", "MADE BY BAR", 100, 2, 3 )
>   session.add(e)
>   session.commit()
>
> then it works fine, now if I try to do this:
>   e = Entity("SPAM", "MADE BY GUMP", 100, 2, 3)
>   session.add(e)
>   session.commit()
>
> then this will throw an IntegrityException. So I have tried using a
> transaction-esque way of doing this, first trying to select the
> interval_id from the intervals table and then setting e's interval_id.
> However this still doesnt work. Has anybody done anything like this
> before? Is there a simple way of doing this, maybe at the level of the
> mapper?
>
> Many thanks in advance,
> Nathan
>
> >
>

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

Reply via email to