Skip to content
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

[sea-orm-cli] Primary & foreign key referencing same column panics #186

Closed
callym opened this issue Sep 22, 2021 · 6 comments · Fixed by #192
Closed

[sea-orm-cli] Primary & foreign key referencing same column panics #186

callym opened this issue Sep 22, 2021 · 6 comments · Fixed by #192
Assignees

Comments

@callym
Copy link

callym commented Sep 22, 2021

Hi, I've got the following SQL, which crashes the generator.
Commenting out the foreign key line, or changing the primary key to PRIMARY KEY (a) makes it work fine, but I'm not sure why, as I think what I'm doing is valid?

CREATE TABLE IF NOT EXISTS foo (
  a TEXT NOT NULL,
  PRIMARY KEY (a)
);

CREATE TABLE IF NOT EXISTS bar (
  a TEXT NOT NULL,
  b TEXT NOT NULL,

  FOREIGN KEY (a) REFERENCES foo (a),
  PRIMARY KEY (a, b)
);

The error I get is:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/callym/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/sea-orm-codegen-0.2.3/src/entity/transformer.rs:69:83

Running v0.2.3

The example is maybe a bit unclear, my use case is trying to store plant information (family, genus, species, etc), where (species name) isn't unique (there's tons of plants with a species name of e.g. 'alba'), but (genus name + species name) is unique.

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 22, 2021

Hi there, it certainly is valid schema.
It is a bug within codegen.
We will fix it as soon as we can.

@billy1624
Copy link
Member

This bug exists in MySQL? Given the MySQL style of sql statements.

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 24, 2021

What was the story @billy1624 ?
I see that it failed at unwrapping, which I think it means that we can avoid the panic by checking not none.
Is there another problem implied, given the title of the PR?

@billy1624
Copy link
Member

It is not related to "primary & foreign key referencing same column cause panics". The bug is that I forgot to ensure the conjunct relation should compose of 2 columns & ref_columns. Fixed on commit 9e584d0

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 25, 2021

The panic has been fixed.

You can try installing the unreleased version of sea-orm-cli 0.2.4 by

cargo install sea-orm-cli --git https://github.com/SeaQL/sea-orm

@tyt2y3 tyt2y3 changed the title Primary & foreign key referencing same column panics [sea-orm-cli] Primary & foreign key referencing same column panics Sep 25, 2021
@tyt2y3
Copy link
Member

tyt2y3 commented Sep 26, 2021

Released in sea-orm-cli 0.2.4 on crates.io

arpancodes pushed a commit to arpancodes/sea-orm that referenced this issue Apr 8, 2022
…to-table-ref

removed `'static` and inplace, added the type `IntoTableRef`.
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

Successfully merging a pull request may close this issue.

3 participants