Replies: 3 comments 3 replies
-
It's hard to help here without knowing what's in your database. The only thing that I can say is that diesel does not cache any query results, so if you get a "Duplicated entry" error that means there is really a duplicated entry in your database. For additional help you would need to provide detailed steps to reproduce the problem starting from a new database. |
Beta Was this translation helpful? Give feedback.
-
Are you sure that |
Beta Was this translation helpful? Give feedback.
-
Maybe you gets cached result from web-server? What happens if you |
Beta Was this translation helpful? Give feedback.
-
T1:create an account with username "abc", result is success.
T2:create an account with username "abc", result is error, error: "Duplicate entry 'abc' for key 'account.username'"
T3:login to mysql, and execute "delete from account where 1;"
T4:replay the action of T2, failed again with error: "Duplicate entry 'abc' for key 'account.username'"
after enable the general log of mysql
T2 with general log:
2024-07-06T12:51:43.202730Z 83 Execute SELECT 1
2024-07-06T12:51:43.203200Z 83 Execute INSERT INTO
account
(username
) VALUES ('abc')T4 with general log:
2024-07-06T12:51:43.202730Z 83 Execute SELECT 1
so it seems a little wired, kind of caching result of unique key?
project layout
. ├── Cargo.lock ├── Cargo.toml ├── migrations │ └── 2024-06-16-125405_create_account │ ├── down.sql │ └── up.sql ├── src │ └── main.rs └── target ├── CACHEDIR.TAG └── debug
up.sql
Cargo.toml
main.rs
/path/to/project/.env
DATABASE_URL=mysql://root:password@localhost/demo
mysql version
mysql --version mysql Ver 8.0.37 for Linux on x86_64 (MySQL Community Server - GPL)
diesel version
init database
run the axum project
T1: create an account with username "abc"
succeed, check the database
T2: create an account with username "abc" again, error response
T3: login to mysql and delete from account
T4: create an account with username "abc" again, go error response again
check the database
need some helps, thank you all.
Beta Was this translation helpful? Give feedback.
All reactions