How to create a table in SeaORM

818 Views Asked by At

I'm trying to see how the TableCreateStatement should be called and where in my code it should live. Looking at the documentation no idea really.

I see I can create a table manually with:

let stmt = sea_query::Table::create()
        .table(super::post::Entity)
        .if_not_exists()
        .col(

but I already have copy-pasted together a pub struct Model and I would like to not repeat myself there.

1

There are 1 best solutions below

0
On

After hunting together through some documentation, this checks out:

let backend = conn.get_database_backend();
let schema = Schema::new(backend);
let table_create_statement = schema.create_table_from_entity(FoursquareGmapsMappings);
let table_create_result = conn.execute(backend.build(&table_create_statement)).await;