Home:ALL Converter>Pandas mysql last inserted id sqlalchemy import create_engine

Pandas mysql last inserted id sqlalchemy import create_engine

Ask Time:2019-07-23T05:12:25         Author:pikas

Json Formatter

I am trying to insert pandas dataframe data into mysql database using sqlalchemy .The table table_test has one column AUTO_INCREMENT. I want to get the value of the AUTO_INCREMENT column and use it in the later part of the program. Below is my code :

from sqlalchemy import create_engine
mysqldb = create_engine("mysql://test:password@localhost/test")
df.to_sql(con=mysqldb, name='table_test',index=False, if_exists='append')
print (mysqldb.insert_id())

However the last print line giving me error .

File "test.py", line 208, in StagingCountLesserThanTarget mysqldb.insert_id() AttributeError: 'Engine' object has no attribute 'insert_id'

how to get the last inserted id in mysql using sqlalchemy?

Author:pikas,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57153788/pandas-mysql-last-inserted-id-sqlalchemy-import-create-engine
yy