Alvie's Blog

SQLAlchemy 获取 AutoField 值

March 17, 2015

f = Foo(bar=x)
# At this point, the object f has been pushed to the DB, 
# and has been automatically assigned a unique primary key id
# is None

# refresh updates given object in the session with its state in the DB
# (and can also only refresh certain attributes - search for documentation)
# is the automatically assigned primary key ID given in the database.


python - sqlalchemy flush() and get inserted id? - Stack Overflow

Written by Alvie Zhang