tursodatabase/turso · error · NotSupportedException

SQLite does not support sequences. See https://go.microsoft.

Error message

SQLite does not support sequences. See https://go.microsoft.com/fwlink/?LinkId=723262 for more information and examples.

What it means

TursoSqliteUpdateSqlGenerator.GenerateNextSequenceValueOperation throws NotSupportedException (SqliteStrings.SequencesNotSupported) whenever EF Core's update pipeline asks SQL for the next value from a sequence. SQLite has no sequence objects, so any model configuration that expects server-generated sequence values fails at SQL-generation time with a link to Microsoft's guidance.

Source

Thrown at bindings/dotnet/src/Turso.EntityFrameworkCore.Sqlite/Update/Internal/TursoSqliteUpdateSqlGenerator.cs:63

    protected override ResultSetMapping AppendSelectAffectedCountCommand(
        StringBuilder commandStringBuilder,
        string name,
        string? schema,
        int commandPosition)
    {
        commandStringBuilder
            .Append("SELECT changes()")
            .AppendLine(SqlGenerationHelper.StatementTerminator)
            .AppendLine();

        return ResultSetMapping.LastInResultSet | ResultSetMapping.ResultSetWithRowsAffectedOnly;
    }

    protected override void AppendRowsAffectedWhereCondition(StringBuilder commandStringBuilder, int expectedRowsAffected)
        => commandStringBuilder.Append("changes() = ").Append(expectedRowsAffected);

    public override string GenerateNextSequenceValueOperation(string name, string? schema)
        => throw new NotSupportedException(SqliteStrings.SequencesNotSupported);

    protected override void AppendUpdateColumnValue(
        ISqlGenerationHelper updateSqlGeneratorHelper,
        IColumnModification columnModification,
        StringBuilder stringBuilder,
        string name,
        string? schema)
    {
        if (columnModification.JsonPath is not (null or "$"))
        {
            stringBuilder.Append("json_set(");
            updateSqlGeneratorHelper.DelimitIdentifier(stringBuilder, columnModification.ColumnName);
            stringBuilder.Append(", '");
            stringBuilder.Append(columnModification.JsonPath);
            stringBuilder.Append("', ");

            if (columnModification.Property is { IsPrimitiveCollection: false })
            {

View on GitHub (pinned to 244cde92a7)

Solutions

  1. Replace UseHiLo with ValueGeneratedOnAdd (SQLite AUTOINCREMENT-style rowid keys) on the key property.
  2. Generate keys client-side (Guid.CreateVersion7(), ULID, or a configurable base) so no server sequence is needed.
  3. Remove modelBuilder.HasSequence(...) calls and any migration operations that create sequences.
  4. Audit the model for HiLo/sequence conventions after switching providers — the exception surfaces at save time, not model build time.

Example fix

// before
modelBuilder.Entity<Order>().Property(o => o.Id).UseHiLo("order_hilo");

// after
modelBuilder.Entity<Order>().Property(o => o.Id).ValueGeneratedOnAdd();
Defensive patterns

Strategy: validation

Validate before calling

// fail fast at startup if the model needs sequences
var usesSequences = modelBuilder.Model.GetEntityTypes()
    .SelectMany(e => e.GetProperties())
    .Any(p => p.GetValueGenerationStrategy().ToString().Contains("Sequence"));
if (usesSequences) throw new InvalidOperationException("Model relies on sequences, which SQLite/Turso does not support");

Try / catch

try { await db.SaveChangesAsync(); }
catch (NotSupportedException ex) when (ex.Message.Contains("sequences")) { /* replace UseHiLo with ValueGeneratedOnAdd or client keys */ }

Prevention

When it happens

Trigger: Configuring a key generator that needs a sequence: UseHiLo("seq"), a HiLoValueGenerator, or modelBuilder.HasSequence(...); also scaffolding/reusing a model authored for the SQL Server or PostgreSQL provider where sequences or HiLo are the default key strategy.

Common situations: Copying an OnModelCreating from an Npgsql/SqlServer app (Npgsql defaults to HiLo on some versions); running EF migrations generated elsewhere against the Turso provider; tutorial code that assumes serial-like behavior.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/02fa740dadaed874. Report an issue: GitHub.