I’m trying to create Migration with Sea ORM, but getting an error when running cargo run up
command from the migration folder.
Migration looks like this:
use sea_orm_migration::prelude::*;
use crate::m20240521_000001_create_table::User;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(UserCountry::Table)
.if_not_exists()
.col(
ColumnDef::new(UserCountry::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(UserCountry::UserId).integer().not_null())
.col(ColumnDef::new(UserCountry::Country).string().not_null())
.col(ColumnDef::new(UserCountry::ApplyToAllSites).boolean().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-user")
.from(UserCountry::Table, UserCountry::UserId)
.to(User::Table, User::Id),
)
.to_owned(),
)
.await;
manager
.create_index(
Index::create()
.if_not_exists()
.name("idx_user_id")
.table(UserCountry::Table)
.col(UserCountry::UserId)
.to_owned(),
)
.await?;
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UserCountry::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum UserCountry {
Table,
Id,
UserId,
Country,
ApplyToAllSites
}
The error I’m receiving is
7 | #[async_trait::async_trait]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<(), DbErr>`, found `()`