Comments (4)
Quick superficial investigation shows that this might be a general SQLite problem in Prisma, not just D1-specific. Requires experimental confirmation.
from prisma.
I can confirm the error.
The error on the webpage is
PrismaClientKnownRequestError: Invalid `prisma.user.deleteMany()` invocation: Foreign key constraint failed on the field: `foreign key`
{
"name": "PrismaClientKnownRequestError",
"code": "P2003",
"clientVersion": "5.14.0",
"meta": {
"modelName": "User",
"field_name": "foreign key"
}
}
The error in the console is
✘ [ERROR] Error in performIO: Error: D1_ERROR: FOREIGN KEY constraint failed
at D1Database._sendOrThrow (cloudflare-internal:d1-api:66:19)
at async D1PreparedStatement.run (cloudflare-internal:d1-api:178:29)
... 2 lines matching cause stack trace ...
at null.<anonymous> (async
file:///Users/j42/Repros/prisma-24293/.wrangler/tmp/dev-MvOEWC/index.js:1707:18) {
[cause]: Error: FOREIGN KEY constraint failed
at D1Database._sendOrThrow (cloudflare-internal:d1-api:67:24)
at async D1PreparedStatement.run (cloudflare-internal:d1-api:178:29)
at async PrismaD1.performIO
(file:///Users/j42/Repros/prisma-24293/node_modules/@prisma/adapter-d1/dist/index.mjs:230:19)
at async PrismaD1.executeRaw
(file:///Users/j42/Repros/prisma-24293/node_modules/@prisma/adapter-d1/dist/index.mjs:222:17)
at null.<anonymous> (async
file:///Users/j42/Repros/prisma-24293/.wrangler/tmp/dev-MvOEWC/index.js:1707:18)
}
It shows there that the error returned by D1 is D1_ERROR: FOREIGN KEY constraint failed
which does not contain any information about the FK name.
from prisma.
Unfortunately, there is nothing we can do about this because SQLite itself does not know the name of the FK.
Example when using sqlite
provider, the same happens:
#10867
Some explanation can be found here
https://sqlite.org/forum/info/26c886864e6cfe7bcfd69b1eb52fa57da500c0b7d8ee17d6bad353c39d14a299
The Foreign Key constraint mechanism works by using a counter of failed constraints. When a constraint fails the counter increments. When a constraint is resolved later on within the same statement, the counter decrements. If at the end of the statement (or transaction) the counter is non-zero, then you get an error.
I think the only thing doable here is to change "field_name": "foreign key"
to "field_name": "<unknown>"
, if that's interesting for you, creating a new issue focussed on this improvement would be better suited I think.
from prisma.
Note that if you wanted to delete all the data in your script, you could first delete the posts and then the users:
await prisma.post.deleteMany();
await prisma.user.deleteMany();
from prisma.
Related Issues (20)
- Running queries in Promise.all() leads to idle zombie database sessions HOT 2
- Enable parameters for data source to be provided as fields on `datasource` instead of connection string arguments
- prisma migrate * commands not working HOT 3
- Schema enum Support Chinese HOT 3
- transaction: bulk ops already in a transaction should not be executed in a new sub transaction HOT 2
- Could not figure out an ID in create HOT 4
- Cannot read properties of undefined (reading 'kind') HOT 4
- Prisma is returning the DateTime in ISOstring() HOT 2
- Generalize and Enhance Readability of "RecordNotFound" Error Message in Prisma Client HOT 1
- Log query params are not escaped
- 2D Array Support HOT 2
- Prisma and OpenTelemetry: has no active context in prisma query event
- Add createManyAndReturn() support for MariaDB
- Missing encoding for special characters for JSON columns in MYSQL HOT 3
- Cannot install prisma engines
- Prisma shouldn't just drop and re-create postgres schema to fix migration issues HOT 1
- [@prisma/instrumentation] Version 15.14.0 onwards using non existing generic in InstrumentationNodeModuleDefinition form @opentelemetry/instrumentation Library HOT 2
- [v5.15.0] bad type of `$extends` HOT 3
- Switching to a new database after startup
- Incorrect MongoDB array behavior when field is `null` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma.