python - sqlalchemy core autoincrement integer column which is part of the unique constraint -
requirement: composite key having auto-incremental value. how define table:
doc_versions = table("doc_versions", metadata, column("id", integer, primary_key=true), column("doc_id", integer,foreignkey("docs.id")), column("version_number", integer, default=select([ func.max(1, 1)])), uniqueconstraint("doc_id","version_number", name="doc_version") )
how initialize version number composite key i.e doc_id + version_number should unique , take next sequence. want use sqlalchemy core 1.0.8
there have been lot of questions similar problems here, , answer (sorry no links, search e.g. 'sqlalchemy autoincrement composite'):
sqlalchemy
can handle autoincrement on integer primary keys.
it's sad, true. can query table ordered doc_id
, version_number
, last row, , increment it. i'm using same method composite keys.
Comments
Post a Comment