SeaQL / SeaQL/sea-orm

Issues with tables that do not have primary/unique keys

Open
#2,141 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:code-gen
Dominant language
Rust
Stars
9.9k
Forks
735
Avg merge
6h 36m
Merged PRs (30d)
8

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the seaorm CLI entity generation with one table that has a primary key and one without, then inspect the generated model and DeriveEntityModel diagnostics. Compare the behavior with the linked SeaORM issue and the pg_partman table requirements. Done means keyless tables can be represented and the resulting compile errors no longer incorrectly implicate unchanged tables.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
cli, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.