@listens_for(Event, 'after_insert')
def after_insert(mapper, connection, target):
 link_table = Version.__table__
 version = Version.query.order_by(Version.id.desc()).first()
 if version:
  version_id = version.id
  connection.execute(link_table.update().where((link_table.c.id == version_id)).values(event_id=target.id))

@ listens_for ( Event , 'after_insert' ) def after_insert ( mapper , connection , target ) : link_table = Version . __table__ version = Version . query . order_by ( Version . id . desc ( ) ) . first ( ) if version : version_id = version . id connection . execute ( link_table . update ( ) . where ( ( link_table . c . id == version_id ) ) . values ( event_id = target . id ) )
update version after insert to db .