9.5.13 Property MySQLCursor.lastrowid

Syntax:

id = cursor.lastrowid

This read-only property returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement or None when there is no such value available. For example, if you perform an INSERT into a table that contains an AUTO_INCREMENT column, lastrowid returns the AUTO_INCREMENT value for the new row. For an example, see Section 5.3, “Inserting Data Using Connector/Python”.

The lastrowid property is like the mysql_insert_id() C API function; see mysql_insert_id().