I would like to set a column default value that is based on another table in my SQLAlchemy model.
Currently I have this:
Column('version', Integer, default=1)
What I need is (roughly) this:
Column('version', Integer, default="SELECT MAX(1, MAX(old_versions)) FROM version_table")
How can I implement this in SQLAlchemy?
The documentation gives the following possibilities for
default:You may look into using a simple function, or you may just be able to use a
select()object.In your case, maybe something along the lines of: