Skip to content

Prisma Migrate fails with defaults on Json when using SQLite #26571

@emmatown

Description

@emmatown

Bug description

Prisma generates invalid SQL when using the Json type with a default value.

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

  1. Create a schema.prisma with the contents from the prisma schema section of this issue
  2. Run prisma db push
  3. Receive the error shown in the logs section of this issue

https://codesandbox.io/p/devbox/prisma-json-default-reproduction-6gqm29?file=%2Fschema.prisma%3A4%2C1

Expected vs. Actual Behavior

I expected Prisma to add the default correctly (in quotes). Instead I got an error from SQLite because Prisma generated invalid SQL.

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

It hasn't worked in a previous version, it has been broken since support for Json in SQLite was added

Workaround

Avoid using default values with the Json scalar

Prisma Schema & Queries

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

model A {
  id Int  @id @default(autoincrement())
  b  Json @default("{\"something\": true}")
}

Logs & Debug Info

This is the result from running prisma db push

Environment variables loaded from .env
Prisma schema loaded from schema.prisma
Datasource "db": SQLite database "dev.db" at "file:./dev.db"
Error: SQLite database error
unrecognized token: "{" in CREATE TABLE "A" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "b" JSONB NOT NULL DEFAULT {"something": true}
) at offset 103
   0: sql_schema_connector::apply_migration::migration_step
           with step=CreateTable { table_id: TableId(0) }
             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:21
   1: sql_schema_connector::apply_migration::apply_migration
             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:10
   2: schema_core::state::SchemaPush
             at schema-engine/core/src/state.rs:504

Environment & Setup

  • OS: macOS
  • Database: SQLite
  • Node.js version: v22.13.1

Prisma Version

prisma                  : 6.4.1
@prisma/client          : 6.4.1
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v22.13.1
TypeScript              : 4.9.5
Query Engine (Node-API) : libquery-engine a9055b89e58b4b5bfb59600785423b1db3d0e75d (at node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli a9055b89e58b4b5bfb59600785423b1db3d0e75d (at node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 6.4.0-29.a9055b89e58b4b5bfb59600785423b1db3d0e75d
Default Engines Hash    : a9055b89e58b4b5bfb59600785423b1db3d0e75d
Studio                  : 0.509.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions