sea-orm
sea-orm copied to clipboard
Mysql sea-orm 1.1 insert bug
trafficstars
When I was using sea-orm 0.12 with MySQL version 8.0.23, data could be written normally even when the primary key wasn't an auto-increment ID.
However, after upgrading to sea-orm 1.1, I encountered insertion failures. Upon investigation, I found that in the newer version, the exec_insert method includes a special check:
let last_insert_id = res.last_insert_id();
// For MySQL, the affected-rows number:
// - The affected-rows value per row is `1` if the row is inserted as a new row,
// - `2` if an existing row is updated,
// - and `0` if an existing row is set to its current values.
// Reference: https://dev.mysql.com/doc/refman/8.4/en/insert-on-duplicate.html
if db_backend == DbBackend::MySql && last_insert_id == 0 {
return Err(DbErr::RecordNotInserted);
}
This check on last_insert_id appears to be affecting my use case, even though the data can actually be written to the database normally.
I'd like to understand:
- Why this check on
last_insert_idwas added? - Is there a better way to handle this for better compatibility?