Hi list I am starting out with sqlalchemy and I am currently struggling with the following problem. In my model I want to establish a many-to-many relation between an association object and another 'normal sqlalchemy' object. This relationship must also follow the association object pattern.
In my code 'PaFi' is an association object, 'Process' is a normal declarative style table and 'PaFiPr' is my desired association object to connect the previous two. This is a sample of the model, showing the relevant part: class PaFiPr(Base): __tablename__ = 'pa_fi_pr' __table_args__ = ( ForeignKeyConstraint(['package_id', 'filetype_id'], ['pa_fi.package_id', 'pa_fi.filetype_id']), {} ) package_id = Column(Integer, primary_key=True) filetype_id = Column(Integer, primary_key=True) process_id = Column(Integer, ForeignKey('process.id'), primary_key=True) process = relation("Process", backref="pafiprs") fileTimeslot = Column(DateTime, index=True) fileArea = Column(String) fileSource = Column(String) expectedFiles = Column(Integer) numActualFiles = Column(Integer) class PaFi(Base): __tablename__ = 'pa_fi' filetype_id = Column(Integer, ForeignKey('filetype.id'), primary_key=True) package_id = Column(Integer, ForeignKey('package.id'), primary_key=True) ftype = relation("Filetype", backref="pafis") pafiprs = relation(PaFiPr, backref="pafi", secondary="pa_fi_pr" primaryjoin="and_(PaFiPr.package_id==PaFi.package_id,"+\ "PaFiPr.filetype_id==PaFi.filetype_id)", secondaryjoin=PaFiPr.filetype_id=="PaFi.filetype_id", foreign_keys=[PaFiPr.package_id, PaFiPr.filetype_id]) fileRole = Column(String) modeVersion = Column(String) class Process(Base): __tablename__ = 'process' id = Column(Integer, primary_key=True) timeslot = Column(DateTime, index=True) processing_mode = Column(String, nullable=False) status = Column(Boolean, nullable=False) pack_area = Column(String, nullable=False) pack_version = Column(String, nullable=False) pack_source = Column(String, nullable=False) package_id = Column(Integer, ForeignKey('package.id')) package = relation(Package, backref="processes") I am getting this error: sqlalchemy.exc.IntegrityError: (IntegrityError) pa_fi_pr.package_id may not be NULL u'INSERT INTO pa_fi_pr (process_id, "fileTimeslot", "fileArea", "fileSource", "expectedFiles", "numActualFiles") VALUES (?, ?, ?, ?, ?, ?)' (1, '2011-02-01 22:00:00.000000', None, None, None, None) I must admit that after having spent much of my day looking at sqla's documentation and various other websites has left me pretty dumbed down. Can someone please help me out? Thanks -- 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.