i used history_meta extension (http://docs.sqlalchemy.org/en/latest/_modules/examples/versioned_history/history_meta.html) sqlalchemy.
the problem not seem work polymorphic identity, @ least when using multiple tables so:
class baseversion(versioned, base): __tablename__ = 'base_version' id = column(integer, primary_key=true) ... __mapper_args__ = { 'polymorphic_identity':'base_version', 'polymorphic_on':type, } (note baseversion uses versioned mixin defined in history_meta)
then there's class inherits baseversion:
class unspecifiedversion(baseversion): __tablename__ = 'unspecified_version' id = column(integer, foreignkey('base_version.id'), primary_key=true) related_base_version_id = column(integer, foreignkey('base_version.id'), index=true) related_base_version = relationship('baseversion', uselist=false, foreign_keys=[related_base_version_id]) __mapper_args__ = { 'polymorphic_identity':'unspecified_version', 'inherit_condition':(related_base_version_id==baseversion.id) } backend db postgres.
trying produce history table ends error:
sqlalchemy.exc.programmingerror: (psycopg2.programmingerror) there no unique constraint matching given keys referenced table "base_version_history" [sql: ' create table unspecified_version_history ( id integer not null, related_base_version_id integer, version integer not null, changed timestamp without time zone, changed_by varchar, primary key (id, version), foreign key(id, related_base_version_id, version) references base_version_history (id, id, version) ) '] now that's weird because base_version_history table has id , version columns.
i got through same error similar. issue appears composite primary keys , composite foreign keys being generated, seen in these last 2 lines of sql:
primary key (id, version), foreign key(id, related_base_version_id, version) references base_version_history (id, id, version) composite foreign keys need find matching composite unique keys (basically). if table created two-column primary key, chances other 1 did too, , foreign key looking three-column unique key. also, same column twice looks wrong: (id, id, version). don't know extension working can't tell how fix it.
Comments
Post a Comment