首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么referentialIntegrity = "prisma“不能防止外键迁移?

为什么referentialIntegrity = "prisma“不能防止外键迁移?
EN

Stack Overflow用户
提问于 2021-12-14 22:55:25
回答 1查看 630关注 0票数 0

我正在尝试使用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模型时,会出现以下错误:

代码语言:javascript
复制
$ 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文件:

代码语言:javascript
复制
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])
}
代码语言:javascript
复制
$ 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

我会非常感谢你的帮助!提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2021-12-15 03:08:57

我已经复制了您的模式,并且遵循了教程,并且所有这些都正常工作。在图像中,您可以看到迁移工作。

顺便说一句:我的prisma版本是3.3.0

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70356527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档