dojoengine/dojo

[BUG] `delete!` causes FOREIGN KEY constraint failed

Closed this issue · 1 comments

Describe the bug
When we use the delete! macro for destroy a model of the following schema

#[derive(PartialEq, Copy, Drop, Serde)]
#[dojo::model]
pub struct Building {
    #[key]
    outer_col: u32,
    #[key]
    outer_row: u32,
    #[key]
    inner_col: u32,
    #[key]
    inner_row: u32,
    category: BuildingCategory,
    produced_resource_type: u8,
    bonus_percent: u32,
    entity_id: ID,
    outer_entity_id: ID,
    paused: bool,
}

with

#[derive(PartialEq, Copy, Drop, Serde, Introspect)]
enum BuildingCategory {
    None,
    Castle,
    Resource,
    Farm,
    FishingVillage,
    Barracks,
    Market,
    ArcheryRange,
    Stable,
    TradingPost,
    WorkersHut,
    WatchTower,
    Walls,
    Storehouse,
}

and

type ID = u32;

it causes torii to error out: 2024-08-19T23:14:17.344771Z ERROR tori_core::engine: Processing event. event_name="StoreDelRecord" error=error returned from database: (code: 787) FOREIGN KEY constraint failed and stop indexing further events

To Reproduce

  • create an entity of the Building model, delete the entity

Additional context
Here's the DB file before the issue happened: https://we.tl/t-NBhB2xVyju

Fixed by alpha.6