Skip to content

[MSSQL] Setting Bytes? (@db.VarBinary(Max)) to null throws "Implicit conversion from nvarchar to varbinary(max)" #29557

Closed

Description

@devFilipe10Brito

Bug description

When updating a Bytes? field mapped to @db.VarBinary(Max) with null using @prisma/adapter-mssql, the query fails with an implicit type conversion error. The adapter is sending the null parameter typed as nvarchar instead of respecting the varbinary(max) column type.

How to reproduce

Schema:

model Pessoa {
  idPessoa              String  @id
  assinaturaBic         Bytes?  @db.VarBinary(Max)
  assinaturaBicExtensao String?
  assinaturaBicNoS3     Boolean
}

Code:

await prisma.pessoa.update({
  where: { idPessoa },
  data: {
    assinaturaBic: null,
    assinaturaBicExtensao: null,
    assinaturaBicNoS3: false,
  },
});

Expected behavior

The field should be set to NULL in the database without errors.

Actual behavior

DriverAdapterError: Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
    at MssqlTransaction.onError (.../node_modules/@prisma/adapter-mssql/dist/index.js:709:11)
    at MssqlTransaction.performIO (.../node_modules/@prisma/adapter-mssql/dist/index.js:704:12)
    at MssqlTransaction.performIO (.../node_modules/@prisma/adapter-mssql/dist/index.js:722:14)
    at MssqlTransaction.executeRaw (.../node_modules/@prisma/adapter-mssql/dist/index.js:692:13)
  cause: {
    originalCode: 'EREQUEST',
    originalMessage: 'Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.',
    kind: 'mssql',
    code: 257
  },
  clientVersion: '7.8.0'

Workaround

Running raw SQL directly works correctly:

UPDATE Pessoa SET assinaturaBic = CONVERT(varbinary(max), NULL) WHERE idPessoa = '...'

Environment

prisma                : 7.8.0
@prisma/client        : 7.8.0
@prisma/adapter-mssql : 7.8.0
OS                    : Windows
Node.js               : 24.15.0
Database              : Microsoft SQL Server 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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