SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.57k stars 461 forks source link

Issues with tables that do not have primary/unique keys #2141

Open gitmalong opened 3 months ago

gitmalong commented 3 months ago

Hi!

When creating a table that does not have a primary key attached

1) Not able to create table that do not has primary key

Workarounds in https://github.com/SeaQL/sea-orm/issues/485 do not work. Using a unique col instead does also not work in my use case with pg_partman (Execution Error: error returned from database: unique constraint on partitioned table must include all partitioning columns).

Motivation: I am trying to make use of https://github.com/pgpartman/pg_partman/blob/master/doc/pg_partman_howto.md#simple-time-based-1-partition-per-day which wants me to create a parent table without having a primary key.

2) Compile errors with misleading error messages

Expected behavior:

5  | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
   |                                   ^^^^^^^^^^^^^^^^^ the trait `sea_orm::IdenStatic` is not implemented for `entities::table_without_primary_key::PrimaryKey`

Actual behavior:

I am getting misleading error messages for tables that have primary keys and were not modified.

5  | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
   |                                   ^^^^^^^^^^^^^^^^^ the trait `sea_orm::IdenStatic` is not implemented for `entities::table_with_primary_key::PrimaryKey`

I found that seaorm cli for does not add #[sea_orm(primary_key)] to all tables when one of the tables is lacking of a primary key.

oskardotglobal commented 1 week ago

It would be great if sea-orm-cli would allow skipping tables without primary keys