0

I have currently finished a project I was working on and while getting ready for production, I stumbled into an error which I cannot manage to fix. Am using planetscale as my database hoster, my project uses nextjs and prismajs. Whenever I run the command

npx prisma db push

I get the following error

Error: target: keep.-.primary: vttablet: rpc error: code = InvalidArgument desc = You have an error in your SQL syntax; check the manual that corresponds to your 
MySQL server version for the right syntax to use near 'id,
    `password` VARCHAR(191) NULL,
    `email` VARCHAR(191) NULL,

    UNIQUE' at line 3 (errno 1064) (sqlstate 42000) (CallerID: t90z5wialstwequ2wfqf): Sql: "CREATE TABLE `User` (\n    `id` VARCHAR(191) NOT NULL,\n    `name` VARCHAR(191) NULL DEFAULT id,\n    `password` VARCHAR(191) NULL,\n    `email` VARCHAR(191) NULL,\n\n    UNIQUE INDEX `User_email_key`(`email`),\n    PRIMARY KEY (`id`)\n) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci", BindVars: {REDACTED}
   0: sql_migration_connector::apply_migration::migration_step
           with step=CreateTable { table_id: TableId(2) }
             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:444

But if I do this on a locally hosted mysql database, everything works fine.

This is my prismajs schema

// 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"
    // 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"
}

//Authorization
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?    @default(dbgenerated("id"))
    password  String?
    email     String?    @unique
    accounts  Account[]
    sessions  Session[]
    documents Document[]
}

model VerificationToken {
    identifier String
    token      String   @unique
    expires    DateTime

    @@unique([identifier, token])
}

//Etc
model Document {
    id         Int       @id @default(autoincrement())
    name       String
    createdAt  DateTime  @default(now())
    expiration DateTime?
    text       String    @db.Text
    categoryId Int?
    User       User?     @relation(fields: [userId], references: [id])
    userId     String?
}

I tried to prototype my schema, but I ended up getting an error which I cannot fix.

csharpdev
  • 31
  • 3

0 Answers0