Open jboxman opened 1 year ago
This works, so it seems to be one of the fields. By brute force I can discover which.
images = await dk.images.findMany({
select: {
id: true,
},
});
So this originates from:
modificationDate DateTime?
Which Prisma derived for me from a database pull.
Presents as:
2022-08-12T21:40:46.248
So this is invalid? Why does Prisma assign a DateTime
column, then? It looks like Prisma doesn't support this native SQLite column type?
@jboxman were you able to work around this?
@maxcountryman, I cheated. I setup a view with the data type that Prisma wants and used the view to transform the underlying column to this "correct" type. I use the view as the relation instead of the underlying table. I'm only doing this for an import from a legacy database, so the new schema conforms to what Prisma expects.
@jboxman when you say, "conforms to what Prisma expects" what do you mean by that? I'm trying to migrate a Postgres dataset to SQLite and I think running into this problem. Prisma was fine with Postgres but apparently DateTime?
is not okay with Prisma + SQLite. (That's not great, because it's the correct data model for my use case.)
@maxcountryman, so this is what I was able to surmise: https://boxman.dev/blog/use-prisma-with-an-sq-lite-datetime-datatype
i also see the following error on SQLite DateTime
column:
PrismaClientKnownRequestError:
Invalid `prisma.post.findMany()` invocation:
Inconsistent column data: Conversion failed: input contains invalid characters
Easiest way I found to reproduce the issue:
Schema:
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
datasource db {
provider = "sqlite"
url = "file:./dev.db"
}
model Model {
id Int @id @default(autoincrement())
date DateTime
}
Code:
const prisma = new PrismaClient()
await prisma.$executeRaw`INSERT INTO Model("date") VALUES ('2022-08-12T21:40:46.248')`
await prisma.model.findMany()
The value is correctly written into DataTime
column on sqlite side, Prisma has a hiccup while reading it though.
Still happens on 5.9.0-dev
Bump. Still relevant. Amazing! A modern library does not fix a problem with the basic feature for a year.
Thanks boxman for exploration. Btw, seems that actual link should now be like this https://dev.to/chingu/use-prisma-with-an-sqlite-datetime-datatype-29o9
Bug description
Pulled from database for new schema, then attempted query with generated client.
Any hints? I have no idea what the
input
is or what characters are invalid. Help?How to reproduce
Run code.
Expected behavior
Query works.
Prisma information
Environment & setup
macOS
node: v16.18.0
SQLite
Prisma Version