UniqueConstraint only represents a constraint being generated along with
CREATE TABLE statements, it doesn't affect any in-python behavior. So
unless you've created your database using your declarative classes,
UniqueConstraint will have no effect.
Chris Lewis wrote:
>
> Hi there,
> I know there's a previous thread, but that's a bit old, so I thought
> I'd make a new one. The UniqueConstraint for the declarative style
> doesn't seem to be working for me. Using code from the last thread, I
> have this:
>
> =====
>
> class Group(Base):
> __tablename__ = "groups"
> __table_args__ = (schema.UniqueConstraint("name", "site"), {})
>
> id = Column(Integer, primary_key = True)
> name = Column(String)
> site = Column(String)
>
> =====
>
> I add to the DB using session.merge(group) in the hope that it'll
> merge the records together, but no luck. It's still placing tons of
> redundant data into the system.
>
> I want to have the ID as a primary key so I don't have to refer to the
> composite when it's used as a foreign key, but not being able to stop
> SQLAlchemy placing redundant data in the table is frustrating! If I
> use the composite primary key, then it stops inserting the junk.
>
> What am I doing wrong?
>
> Thank you!
> Chris Lewis
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---