Skip to content

Cyclic migration dependencies #503

@xelab04

Description

@xelab04

I have a model which refers to another through the ForeignKey<> type:

#[model]
pub struct Posts {
    #[model(primary_key)]
    pub id: Auto<i64>,
    pub tag: ForeignKey<Tags>,
}

And the model it refers to:

#[model]
pub struct Tags {
    #[model(primary_key)]
    pub id: Auto<i64>,
}

I created a migration through cot migration make. When running, the following error is obtained:

failed to run the Cot project: ErrorImpl { inner: WithStatusCode(ErrorImpl { inner: MigrationError(MigrationSortError(CycleDetected(CycleDetected))), status_code: Some(500), .. }), status_code: None, .. }

The migration file contained the following, and setting it to an empty array solved the issue:

const DEPENDENCIES: &'static [::cot::db::migrations::MigrationDependency] = &[
        ::cot::db::migrations::MigrationDependency::model(
            <crate::Tags::Tags as ::cot::db::Model>::APP_NAME,
            <crate::Tags::Tags as ::cot::db::Model>::TABLE_NAME,
        ),
    ];

https://git.alexbissessur.dev/alex/alexbissessur.dev/src/branch/main/src/models The repo link, if that can give some extra context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions