外键约束中引用的 SeaORM 列“owner_id”不存在

FRo*_*tri 2 sql postgresql rust sea-orm

我在 SeaORM、Rust 和 Postgres 上遇到了错误,我是数据库领域的新手,如果这是一个新手问题,那么很抱歉。我想使用 sea-orm-cli 刷新迁移,但出现此错误Execution Error: error returned from database: column "owner_id" referenced in foreign key constraint does not exist

该命令的完整输出如下:

Running `cargo run --manifest-path ./migration/Cargo.toml -- fresh -u postgres://postgres@localhost:5432/task_manager`
    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `migration/target/debug/migration fresh -u 'postgres://postgres@localhost:5432/task_manager'`
Dropping table 'seaql_migrations'
Table 'seaql_migrations' has been dropped
Dropping table 'owner'
Table 'owner' has been dropped
Dropping all types
Applying all pending migrations
Applying migration 'm20221106_182043_create_owner_table'
Migration 'm20221106_182043_create_owner_table' has been applied
Applying migration 'm20221106_182552_create_comment_table'
Execution Error: error returned from database: column "owner_id" referenced in foreign key constraint does not exist
Run Code Online (Sandbox Code Playgroud)

我认为这可能是我在名为 的文件中的代码有问题m20221106_182552_create_comment_table.rs,但我查看了它,似乎不是问题。

Running `cargo run --manifest-path ./migration/Cargo.toml -- fresh -u postgres://postgres@localhost:5432/task_manager`
    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `migration/target/debug/migration fresh -u 'postgres://postgres@localhost:5432/task_manager'`
Dropping table 'seaql_migrations'
Table 'seaql_migrations' has been dropped
Dropping table 'owner'
Table 'owner' has been dropped
Dropping all types
Applying all pending migrations
Applying migration 'm20221106_182043_create_owner_table'
Migration 'm20221106_182043_create_owner_table' has been applied
Applying migration 'm20221106_182552_create_comment_table'
Execution Error: error returned from database: column "owner_id" referenced in foreign key constraint does not exist
Run Code Online (Sandbox Code Playgroud)

我正在关注SeaQL 团队的官方教程,但我不知道是否有过时的内容,希望你能帮助我。

Qwe*_*tie 5

您在评论表中缺少 OwnerId 列。您必须先创建它,然后在其上创建 FK 约束。

看到教程里有

                .col(ColumnDef::new(Chef::BakeryId).integer().not_null())
                .foreign_key(
                    ForeignKey::create()
                        .name("fk-chef-bakery_id")
                        .from(Chef::Table, Chef::BakeryId)
                        .to(Bakery::Table, Bakery::Id),
                )
Run Code Online (Sandbox Code Playgroud)