8000 Mysql sea-orm 1.1 insert bug · Issue #2568 · SeaQL/sea-orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Mysql sea-orm 1.1 insert bug #2568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mashirooooo opened this issue Apr 16, 2025 · 3 comments
Open

Mysql sea-orm 1.1 insert bug #2568

mashirooooo opened this issue Apr 16, 2025 · 3 comments

Comments

@mashirooooo
Copy link

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:

  1. Why this check on last_insert_id was added?
  2. Is there a better way to handle this for better compatibility?
@mashirooooo mashirooooo changed the title Mysql 1.1 insert bug Mysql sea-orm 1.1 insert bug Apr 16, 2025
@tyt2y3
Copy link
Member
tyt2y3 commented Apr 16, 2025

It's added to support onconflict do nothing #2244
you can consume (ignore) this error by https://docs.rs/sea-orm/latest/sea_orm/query/struct.Insert.html#method.do_nothing

you can propose an idea for some new API / params as long as it's not breaking

@mashirooooo
Copy link
Author

I believe this issue was introduced to support onconflict do nothing for MySQL, which shouldn't have been necessary. This is actually normal insertion behavior rather than an exceptional case.

@mashirooooo
Copy link
Author

It's added to support onconflict do nothing #2244用于支持 onconflict do nothing #2244 you can consume (ignore) this error by https://docs.rs/sea-orm/latest/sea_orm/query/struct.Insert.html#method.do_nothing你可以通过 https://docs.rs/sea-orm/latest/sea_orm/query/struct.Insert.html#method.do_nothing 来消费(忽略)这个错误

you can propose an idea for some new API / params as long as it's not breaking你可以提出一些新的 API / 参数建议,只要它们不破坏现有功能即可

When I declare a primary key of type String using #[sea_orm(primary_key)], it defaults auto_increment to true, which caused the aforementioned issue. Should the macro automatically set auto_increment to false when the primary key is of a non-auto-incrementable data type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0