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 generates invalid code if a table has no primary key #126

Closed
nicoulaj opened this issue Sep 3, 2021 · 3 comments
Closed

sea-orm-cli generates invalid code if a table has no primary key #126

nicoulaj opened this issue Sep 3, 2021 · 3 comments

Comments

@nicoulaj
Copy link

nicoulaj commented Sep 3, 2021

With given schema:

create table tag
(
    id bigint generated by default as identity
        constraint tag_pkey
            primary key
);

sea-orm-cli generate outputs:

impl PrimaryKeyTrait for PrimaryKey {
    fn auto_increment() -> bool {
        true
    }
}

instead of:

impl PrimaryKeyTrait for PrimaryKey {
    type ValueType = i64;
    fn auto_increment() -> bool {
        true
    }
}

Tested with sea-orm-cli 0.1.3
related: SeaQL/sea-schema#13

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 3, 2021

Yes, we were in the process of a release.
Please run cargo install sea-orm-cli again to update to sea-orm-cli/0.2.0.
Going forward, we will pair a sea-orm-cli release with a corresponding sea-orm release.

@nicoulaj
Copy link
Author

nicoulaj commented Sep 3, 2021

Ha yes my bad, I can confirm this works fine on 0.2.0.

Another small issue though: if a table has no primary key, it generates invalid code instead of skipping it or throwing a proper error, eg:

create table test
(
    id         bigint generated by default as identity
);

generates:

impl PrimaryKeyTrait for PrimaryKey {
    type ValueType = ;
    fn auto_increment () -> bool {
        true
    }
}

@tyt2y3 tyt2y3 changed the title sea-orm-cli does not generate PrimaryKeyTrait::ValueType sea-orm-cli generates invalid code if a table has no primary key Sep 3, 2021
@tyt2y3
Copy link
Member

tyt2y3 commented Sep 3, 2021

Thank you for your report. I think currently SeaORM requires an Entity to have a primary key.
Though, it does not necessarily to be an actual primary key in the database table.
This behavior is common to other ORM too (AFAIK).

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

No branches or pull requests

3 participants