I am following the official docs to setup next-auth with prisma: https://next-auth.js.org/adapters/prisma. After copying these models (Session, Account, VerificationToken) into my schema.prisma
I get the following error when I try to do a prisma db push
.
Am I missing something? How do I correct this issue?
npx prisma db push
:
Error: foreign key constraints are not allowed, see https://vitess.io/blog/2021-06-15-online-ddl-why-no-fk/
0: sql_migration_connector::apply_migration::migration_step
with step=AddForeignKey { foreign_key_id: ForeignKeyId(0) }
at migration-engine/connectors/sql-migration-connector/src/apply_migration.rs:21
1: sql_migration_connector::apply_migration::apply_migration
at migration-engine/connectors/sql-migration-connector/src/apply_migration.rs:10
2: migration_core::state::SchemaPush
at migration-engine/core/src/state.rs:381
server/prisma/schema.prisma
:
datasource db {
provider = "mysql"
// NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url = env("DATABASE_URL")
// relationMode = "prisma"
}
generator client {
provider = "prisma-client-js"
}
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
enum Role {
hacker
mentor
sponsor
}
model User {
id String @id @default(cuid())
email String @unique
password String
role Role @default(hacker)
accounts Account[]
sessions Session[]
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
Adding relationMode = "prisma"
datasource db
allows me to run npx prisma db push
successfully but then my @relation
s show errors in vscode and when I hover my cursor over it shows:
With `relationMode = "prisma"`, no foreign keys are used, so relation fields will not benefit from the index usually created by the relational database under the hood. This can lead to poor performance when querying these fields. We recommend adding an index manually. Learn more at https://pris.ly/d/relation-mode-prisma-indexes"
I'm not too sure what this means but I think I want to keep these @relation
s rather than doing it "manually" as the error suggests.