On Sun, 2013-02-24 at 13:34:10 +0100, robert rottermann wrote: > The following tables > tblPerson, tblFlag > are linked using the association table tblPerson_has_Flag. > > this works fine if I explicitly define columns to be part of foreign > keys as shown in tblPerson_has_Flag below. > what I wanted to do, but failed was: > in tblPerson_has_Flag insted of marking the columns to be part of a > fk to have the following construct > __table_args__ = ( > sa.ForeignKeyConstraint( > ['tblPerson_id'], [u'tblPerson.id'], > ['tblFlag_id'], [u'tblFlag.id'], > ), > sa.PrimaryKeyConstraint(u'tblPerson_id', u'tblFlag_id'), {} > )
If I understand correctly, you can't use ForeignKeyConstraint, because it is used to create a single foreign key (which can be a composite foreign key if it consists of multiple columns), while in your case there are two separate foreign keys pointing to two different tables. Define your association object like this: class tblPerson_has_Flag(Base): __tablename__ = 'tblPerson_has_Flag' tblPerson_id = sa.Column( mysql.INTEGER(display_width=11), sa.ForeignKey('tblPerson.id'), primary_key=True, autoincrement=False ) tblFlag_id = sa.Column( mysql.INTEGER(display_width=11), sa.ForeignKey('tblFlag.id'), primary_key=True, autoincrement=False ) This will create a composite primary key constraint and two separate foreign key constraints. -- Audrius Kažukauskas http://neutrino.lt/
pgpmldaVSb3TD.pgp
Description: PGP signature