我正在尝试使用prisma和PlanetScale来设置PlanetScale。Planetscale不允许外键,但是Prisma允许禁用外键:https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-integrity
这个问题得到了广泛的讨论(https://github.com/prisma/prisma/issues/7292),甚至有一个看起来应该有效的例子(https://templates.netlify.com/template/nextjs-planetscale-starter/)。
我已经建立了我的行星比例尺数据库,可以连接到它。但是,当我尝试应用NextAuth模型时,会出现以下错误:
$ npx prisma migrate dev
...
Database error code: 1317
Database error:
Foreign keys cannot be created on this database. Learn more how to handle this: https://pris.ly/d/migrate-no-foreign-keys如果我使用referentialIntegrety标志,prisma为什么要创建外键?我在这里遗漏了什么或者误解了什么?
schema.prisma文件:
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
referentialIntegrity = "prisma"
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
model Account {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.VarChar(500)
access_token String? @db.VarChar(500)
refresh_token_expires_in Int?
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
oauth_token_secret String?
oauth_token String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
expires DateTime
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String?
}
model User {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String?
email String? @unique
password String?
emailVerified DateTime?
image String?
role String? @default("user")
accounts Account[]
sessions Session[]
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}$ npx prisma -v
Environment variables loaded from .env
prisma : 3.6.0
@prisma/client : 3.6.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt dc520b92b1ebb2d28dc3161f9f82e875bd35d727 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : dc520b92b1ebb2d28dc3161f9f82e875bd35d727
Studio : 0.440.0
Preview Features : referentialIntegrity我会非常感谢你的帮助!提前感谢!
发布于 2021-12-15 03:08:57
https://stackoverflow.com/questions/70356527
复制相似问题