Skip to content

Argument M is out of range for Native type NVarChar(4000) of SQL Server #5287

@divyenduz

Description

@divyenduz

Bug description

prisma introspect with native types produces invalid schema.

How to reproduce

Steps to reproduce the behavior:

  1. Deploy this SQL
CREATE TABLE [dbo].[ErrorLog](
	[ErrorLogID] [int] IDENTITY(1,1) NOT NULL,
	[ErrorMessage] [nvarchar](4000) NOT NULL,
 CONSTRAINT [PK_ErrorLog_ErrorLogID] PRIMARY KEY CLUSTERED 
(
	[ErrorLogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
  1. Run prisma introspect (with nativeTypes flag)

  2. Generated schema.prisma

model ErrorLog {
  ErrorLogID   Int    @id @default(autoincrement()) @db.Int
  ErrorMessage String @db.NVarChar(4000)
}
  1. Run prisma validate
Error: Error: Schema parsing
error: Argument M is out of range for Native type NVarChar(4000) of SQL Server: Length can range from 1 to 2000. For larger sizes, use the `Max` variant.
  -->  schema.prisma:13
   | 
12 |   ErrorLogID   Int    @id @default(autoincrement()) @db.Int
13 |   ErrorMessage String @db.NVarChar(4000)
14 | }

-->

Prisma information

(base) divyendusingh [prisma-explitit-panic]$ yarn prisma --version                                                                                                                  130 ↵
yarn run v1.22.4
$ /Users/divyendusingh/Documents/prisma/triage/prisma-explitit-panic/node_modules/.bin/prisma --version
  tryLoadEnv Environment variables not found at null +0ms
  tryLoadEnv Environment variables not found at undefined +1ms
  tryLoadEnv No Environment variables loaded +0ms
@prisma/cli          : 2.16.0-dev.17
@prisma/client       : 2.16.0-dev.17
Current platform     : darwin
Query Engine         : query-engine d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt d621d9b01ebb4c8fcd3adeaf3421e0149c676c58 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Studio               : 0.343.0
Preview Features     : nativeTypes

Databases where this happens:

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions