Conversion failed when converting from a character string to uniqueidentifier.
See original GitHub issueHi Prisma Team! My Prisma Client just crashed. This is the report:
Versions
| Name | Version |
|---|---|
| Node | v14.15.1 |
| OS | windows |
| Prisma Client | 2.17.0 |
| Query Engine | undefined |
| Database | undefined |
Query
query {
findManytable(where: {
Id: "X"
}) {
Id
Value
}
}
Logs
nvironment variables not found at undefined
prisma:tryLoadEnv No Environment variables loaded
prisma:client { clientVersion: '2.17.0' }
prisma:engine { cwd: 'C:\\temp\\prisma-issue' }
prisma:engine Search for Query Engine in C:\temp\prisma-issue\node_modules\.prisma\client
prisma:engine Search for Query Engine in C:\temp\prisma-issue\node_modules\.prisma\client
prisma:engine {
prisma:engine flags: [
prisma:engine '--enable-experimental=microsoftSqlServer',
prisma:engine '--enable-raw-queries',
prisma:engine '--port',
prisma:engine '54855'
prisma:engine ]
prisma:engine }
prisma:engine stdout Starting a mssql pool with 33 connections.
prisma:engine stdout TLS encryption is not enabled. All traffic including the login credentials are not encrypted.
prisma:engine stdout Database change from 'd2i_demoscorecard_3' to 'master'
prisma:engine stdout Changed database context to 'd2i_demoscorecard_3'.
prisma:engine stdout SQL collation change from None to None
prisma:engine stdout Microsoft SQL Server�� version 537395215
prisma:engine stdout Packet size change from '4096' to '4096'
prisma:engine stdout Started http server on http://127.0.0.1:54855
prisma:engine Search for Query Engine in C:\temp\prisma-issue\node_modules\.prisma\client
prisma:engine stdout Conversion failed when converting from a character string to uniqueidentifier.
prisma:engine {
prisma:engine error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Error occurred during query execution:
prisma:engine ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(TokenError { code: 8169, state: 2, class: 16, message: "Conversion failed when converting from a character string to uniqueidentifier.", server: "MINIBEAST", procedure: "", line: 1 }) })
prisma:engine at NodeEngine.graphQLToJSError (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:27156:14)
prisma:engine at NodeEngine.request (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:27052:24)
prisma:engine at processTicksAndRejections (internal/process/task_queues.js:93:5)
prisma:engine at async cb (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:78659:26)
prisma:engine at async main (C:\temp\prisma-issue\index.js:5:16) {
prisma:engine clientVersion: '2.17.0'
prisma:engine }
prisma:engine }
prisma:engine stdout Conversion failed when converting from a character string to uniqueidentifier.
prisma:engine {
prisma:engine error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Error occurred during query execution:
prisma:engine ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(TokenError { code: 8169, state: 2, class: 16, message: "Conversion failed when converting from a character string to uniqueidentifier.", server: "MINIBEAST", procedure: "", line: 1 }) })
prisma:engine at NodeEngine.graphQLToJSError (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:27156:14)
prisma:engine at NodeEngine.request (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:27052:24)
prisma:engine at processTicksAndRejections (internal/process/task_queues.js:93:5)
prisma:engine at async cb (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:78659:26)
prisma:engine at async main (C:\temp\prisma-issue\index.js:5:16) {
prisma:engine clientVersion: '2.17.0'
prisma:engine }
prisma:engine }
prisma:engine stdout Conversion failed when converting from a character string to uniqueidentifier.
prisma:engine {
prisma:engine error: PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: Error occurred during query execution:
prisma:engine ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(TokenError { code: 8169, state: 2, class: 16, message: "Conversion failed when converting from a character string to uniqueidentifier.", server: "MINIBEAST", procedure: "", line: 1 }) })
prisma:engine at NodeEngine.graphQLToJSError (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:27156:14)
prisma:engine at NodeEngine.request (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:27052:24)
prisma:engine at processTicksAndRejections (internal/process/task_queues.js:93:5)
prisma:engine at async cb (C:\temp\prisma-issue\node_modules\@prisma\client\runtime\index.js:78659:26)
prisma:engine at async main (C:\temp\prisma-issue\index.js:5:16) {
prisma:engine clientVersion: '2.17.0'
prisma:engine }
prisma:engine }
Client Snippet
const { PrismaClient } = require("@prisma/client");
async function main() {
const client = new PrismaClient();
await client.$connect();
const data = await client.table.findMany({
where: { Id: "test" },
});
console.log(data);
client.$disconnect();
}
main();
Schema
model table {
Id String @id @default(dbgenerated("newid()")) @db.UniqueIdentifier
Value Int
}
Prisma cannot handle the SQL error when trying to match a string to UniqueIdentifier
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Conversion failed when converting from a character string ...
The error message is Conversion failed when converting from a character string to uniqueidentifier. The GUIDs are the ones that I got when...
Read more >SQL Conversion failed when converting from a character ...
SQL Conversion failed when converting from a character string to uniqueidentifier. DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Read more >Conversion failed when converting from a character string ...
The text string '@siteId' can't be converted into a uniqueidentifier for that join, and will result in the error you mentioned:
Read more >Conversion failed when converting from a character string ...
Table has unique identifier column and newid() was inserted into the table. error message is displayed. How's that?
Read more >Conversion failed when converting from a character string ...
This error message appears when you try to convert an invalid character string to uniqueidentifier . Consequences: The T-SQL statement can be ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

That is what we ended up doing! We used https://github.com/NicolasDeveloper/guid-typescript to make sure, only valid GUIDs can be used.
I can reproduce the crash with above query and schema. Here is a packaged reproduction: https://github.com/harshit-test-org/prisma-issue-5869
We should look into this and fix it.