如何修复NextAuth与Prisma为mysql指定的键太长-错误

tsm1rwdh  于 2022-11-21  发布在  Mysql
关注(0)|答案(1)|浏览(111)

我愿意使用NextAuth与Prisma适配器与Mysql(5.7.36)数据库,但我得到以下错误。

Error: Specified key was too long; max key length is 1000 bytes
   0: sql_migration_connector::apply_migration::migration_step
           with step=CreateTable { table_id: TableId(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

如果没有nextauth,我可以做基本的CRUD操作,没有任何问题。
根据文档(https://next-auth.js.org/adapters/prisma),我已经遵循了所有的步骤,如。
1.已创建名称为prisma_mysql的数据库
1.已在.env文件中添加数据库urs。数据库URL为(密码为空)

DATABASE_URL="mysql://root:@localhost:3306/prisma_mysql?schema=public"

1.安装了所需的依赖项npm安装下一个验证@prisma/客户端@下一个验证/prisma适配器npm安装prisma --save-dev
1.现在这里是shcema我试图创建表,但得到的关键字太长的错误。

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

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)
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  accounts      Account[]
  sessions      Session[]
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

我想使用mysql,请让我知道修复。

rxztt3cl

rxztt3cl1#

已访问phpmyadmin〉点击SQL已粘贴

SET GLOBAL default_storage_engine = 'InnoDB';

对我有用。

相关问题