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

CLI can't generate entity with foreign keys ref id from tables in sqlite #635

Closed
duskmoon314 opened this issue Mar 27, 2022 · 3 comments
Closed

Comments

@duskmoon314
Copy link

Description

I'm trying to build my own ledger program. I have some tables with foreign keys, but when executing sea-orm-cli I come across this error:

sea-orm-cli generate entity -u sqlite:///path/to/test.db -o test
thread 'main' panicked at 'Ident is not allowed to be empty; use Option<Ident>', ~/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/proc-macro2-1.0.36/src/fallback.rs:686:9
stack backtrace:
   0: std::panicking::begin_panic
   1: proc_macro2::fallback::Ident::_new
   2: proc_macro2::Ident::new
   3: quote::__private::mk_ident
   4: sea_orm_codegen::entity::relation::Relation::get_ref_column_camel_case

I take a look at the source code and it seems right:

pub fn get_ref_column_camel_case(&self) -> Ident {
    format_ident!("{}", self.ref_columns[0].to_camel_case())
}

So I assume it may correspond to the structure of tables in sqlite. I create a new database with simple tables to try again:

Steps to Reproduce

  1. Exec sqlite3 test1.db "VACUUM;" to create a new empty database

  2. Use DataGrip to create two tables: class(id) and student(id, class). student.class is foreign key, ref class.id

    create table class
    (
        id integer not null
            constraint class_pk
                primary key autoincrement
    );
    
    create unique index class_id_uindex
        on class (id);
    
    create table student
    (
        id    integer not null
            constraint student_pk
                primary key autoincrement,
        class integer not null
            constraint class
                references class
                on update cascade on delete cascade
    );
    
    create unique index student_id_uindex
        on student (id);
  3. Exec sea-orm-cli generate entity -u sqlite:///path/to/test1.db -o test. ERROR occurred!

  4. Add a column name: text to table class, change student.class to ref class.name

    CREATE TABLE "student"
    (
        id    integer not null
            constraint student_pk
                primary key autoincrement,
        class text    not null
            constraint class
                references class (name)
                on update cascade on delete cascade
    )
  5. Exec sea-orm-cli generate entity -u sqlite:///path/to/test1.db -o test again. SUCCESS!

Expected Behavior

sea-orm-cli can handle relations with foreign keys point to column id.

Actual Behavior

Now cli can not handle.

Reproduces How Often

Every time in my tries.

Versions

  • sea-orm-cli v0.7.1

Additional Information

@duskmoon314
Copy link
Author

A workaround: specify the column name in the generated SQL. 🤣

@tyt2y3
Copy link
Member

tyt2y3 commented Apr 10, 2022

This is a duplicate of SeaQL/sea-schema#101

@duskmoon314
Copy link
Author

This is a duplicate of SeaQL/sea-schema#101

Oh, it is.

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

2 participants