Open nag763 opened 2 years ago
Update : I thought it was happening when using several primary keys for a table, but it also happened with the expected example I was about to provide
Here is the link to the project summing up the issue
Branch issue, the one described here : https://github.com/nag763/sea-orm-issue-662
Branch issue_2 , the one that happened when I tried to show the expected behavior : https://github.com/nag763/sea-orm-issue-662/tree/issue_2
The difference between the two branches is the sql_init/1_schema.sql file that has for the issue branch three primary keys, and for the issue2 branch only one. The entities generated in consequence by the sea-orm-cli are thus different.
To build any of the branch, use docker-compose up command
Hey @nag763, I'm sorry about the delay...
The schema seems a bit odd to me. I feel like the primary key is just the id
column with auto-increment. Of cause, you can add a unique key: (id, home_team_id, away_team_id)
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "GAME")]
pub struct Model {
#[sea_orm(primary_key)] // Imply auto_increment = true
pub id: i32,
pub home_team_id: i32,
pub away_team_id: i32,
}
But yeah, I have to admit there is a "bug" inside the insert when the (composite) primary key is partially auto-incremented
Hello @billy1624 ,
No worries for the delay ! :+1:
Indeed the schema is a bit complicated, I had to refactor it anyway. :laughing:
I just kept the issue open in case it could cover some " more legit " bugs.
In SeaORM, composite primary key must have all columns set to be auto_increment = false
. This constraint might be very difficult to workaround.
Actually, we might be able to make the macro check for this and refuse to compile.
Description
When inserting a value in a table with several primary keys and using the default value for an auto-incremented one, the insert fails.
Known to be reproducible with MySQL.
Steps to Reproduce
Table schema :
Entity generated :
Let's note that :
Expected Behavior
The entity should be inserted in the table, and no error should be thrown.
Actual Behavior
The entity is inserted in the table, but an error is thrown
Reproduces How Often
On every insert for a mysql database
Versions
Additional Information
A sample project will be shared