clockworklabs/SpacetimeDB · error

AddSequence: `{sequence_name}` not found in new module def

Error message

AddSequence: `{sequence_name}` not found in new module def

What it means

Applying AddSequence: the diff plans creating a sequence (e.g. from #[auto_inc] columns), but no table in the new module def stores it (plan.new.find_storing_table returns None). The sequence key does not resolve in the new defs - plan/def desync. The publish aborts before the sequence is created.

Source

Thrown at crates/engine/src/update.rs:503

                    .table_id_from_name_mut(tx, &table_full_name)?
                    .expect("table should exist in the database for AddConstraint");
                let mut constraint_schema =
                    ConstraintSchema::from_module_def(owning_def, constraint_def, table_id, ConstraintId::SENTINEL);

                // Apply namespace prefix for submodule constraints
                constraint_schema.constraint_name = namespace.join_raw(&constraint_schema.constraint_name);
                log!(
                    logger,
                    "Adding constraint `{constraint_name}` on table `{table_full_name}`"
                );
                stdb.create_constraint(tx, constraint_schema)?;
            }
            spacetimedb_schema::auto_migrate::AutoMigrateStep::AddSequence(key) => {
                let (namespace, sequence_name) = key;
                let (owning_def, table_def) = plan
                    .new
                    .find_storing_table(namespace, sequence_name)
                    .ok_or_else(|| anyhow::anyhow!("AddSequence: `{sequence_name}` not found in new module def"))?;
                let table_full_name = joined(namespace, &table_def.name);
                let sequence_def: &SequenceDef = plan.new.lookup(key).ok_or_else(|| {
                    anyhow::anyhow!("AddSequence: sequence `{sequence_name}` not found in new module def")
                })?;
                let table_id = stdb.table_id_from_name_mut(tx, &table_full_name)?.unwrap();
                let table_schema = stdb.schema_for_table_mut(tx, table_id)?;

                log!(logger, "Adding sequence `{sequence_name}` to table `{table_full_name}`");
                let mut sequence_schema =
                    SequenceSchema::from_module_def(owning_def, sequence_def, table_schema.table_id, 0.into());

                // Apply namespace prefix for submodule sequences
                sequence_schema.sequence_name = namespace.join_raw(&sequence_schema.sequence_name);
                stdb.create_sequence(tx, sequence_schema)?;
            }
            spacetimedb_schema::auto_migrate::AutoMigrateStep::RemoveSequence(key) => {
                let (namespace, sequence_name) = key;
                let (_owning_def, table_def) = plan

View on GitHub (pinned to 6dee26c6ef)

Solutions

  1. Clean-rebuild and republish.
  2. Add the sequence/auto_inc column in its own publish with the table otherwise unchanged.
  3. Keep the owning table's stored name and module path stable; pin with #[table(name = "...")].
  4. Align toolchain versions across builds publishing the same database.
  5. Dev: spacetime publish --delete-data <db>.
  6. Report persistent cases with the module diff.

Example fix

// before: add #[auto_inc] and rename the table in one publish
#[spacetimedb::table(name = "members")] // was `players`
pub struct Member { #[auto_inc] pub id: u64 }

// after: two publishes
// 1) #[spacetimedb::table(name = "players")] struct Player { #[auto_inc] pub id: u64 }
// 2) rename the table separately
Defensive patterns

Strategy: validation

Validate before calling

use spacetimedb_schema::auto_migrate::AutoMigrateStep;
for step in &plan.steps {
    if let AutoMigrateStep::AddSequence((namespace, sname)) = step {
        if plan.new.find_storing_table(namespace, sname).is_none() {
            anyhow::bail!("new def lacks storing table for sequence {}", sname);
        }
    }
}

Type guard

fn sequence_stores_in_new_def(plan: &AutoMigratePlan, ns: &str, sname: &str) -> bool {
    plan.new.find_storing_table(ns, sname).is_some()
}

Try / catch

match update_database(&stdb, tx, &plan, ...).await {
    Err(e) if e.to_string().contains("AddSequence")
        && e.to_string().contains("not found in new module def") => {
        // Split publishes: add auto_inc with the table unchanged; refactor later.
    }
    result => result?,
}

Prevention

When it happens

Trigger: Adding #[auto_inc]/sequence columns while renaming the table or the sequenced column in the same publish; sequence auto-name drift between the def the planner saw and the def being applied (different SDK/compiler versions).

Common situations: Introducing auto-increment IDs during a table refactor; version upgrades between publishes; submodule moves of tables gaining sequences.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/30921dde8694b63e. Report an issue: GitHub.