Closed fan-tastic-z closed 1 month ago
According to the example in the document, using enumeration in migration will prompt an error
https://www.sea-ql.org/SeaORM/docs/migration/writing-migration/#schema-creation-methods
use sea_orm::{EnumIter, Iterable}; use sea_orm_migration::prelude::*; #[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(Post::Table) .if_not_exists() .col( ColumnDef::new(Post::Id) .integer() .not_null() .auto_increment() .primary_key(), ) .col(ColumnDef::new(Post::Title).string().not_null()) .col(ColumnDef::new(Post::Text).string().not_null()) .col( ColumnDef::new(Post::Category) .enumeration(Alias::new("category"), Category::iter()), ) .to_owned(), ) .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(Post::Table).to_owned()) .await } } #[derive(DeriveIden)] enum Post { Table, Id, Title, Text, Category, } #[derive(Iden, EnumIter)] pub enum Category { #[iden = "Feed"] Feed, #[iden = "Story"] Story, }
Execute sea-orm-cli migrate up
sea-orm-cli migrate up
Applying all pending migrations Applying migration 'm20220101_000001_create_table' Execution Error: error returned from database: type "category" does not exist Fail to run migration
sea-orm-cli version: sea-orm-cli 0.12.10 sea-orm-migration: 0.12.0 database: postgres
Description
According to the example in the document, using enumeration in migration will prompt an error
https://www.sea-ql.org/SeaORM/docs/migration/writing-migration/#schema-creation-methods
Execute
sea-orm-cli migrate up
sea-orm-cli version: sea-orm-cli 0.12.10 sea-orm-migration: 0.12.0 database: postgres