Search code examples
javascripttypescriptnext.jsprismasupabase

The column `EventChart.åå` does not exist in the current database


I've been building a dashboard app with Prisma, Next.js and supabase.

When I request a get method, prisma says that column EventChart.åå does not exist, which I've never used this weird alphabet "åå".

Here's the error:

PrismaClientKnownRequestError: 
Invalid `prisma.eventChart.findMany()` invocation:


The column `EventChart.åå` does not exist in the current database.
    at ai.handleRequestError (/Users/name/Desktop/unien-dashboard-app/unien-dashboard/dashboard/node_modules/@prisma/client/runtime/library.js:126:6775)
    at ai.handleAndLogRequestError (/Users/name/Desktop/unien-dashboard-app/unien-dashboard/dashboard/node_modules/@prisma/client/runtime/library.js:126:6109)
    at ai.request (/Users/name/Desktop/unien-dashboard-app/unien-dashboard/dashboard/node_modules/@prisma/client/runtime/library.js:126:5817)
    at async l (/Users/name/Desktop/unien-dashboard-app/unien-dashboard/dashboard/node_modules/@prisma/client/runtime/library.js:131:9709)
    at async GET (webpack-internal:///(rsc)/./app/api/eventChart/route.ts:18:27)
    at async /Users/name/Desktop/unien-dashboard-app/unien-dashboard/dashboard/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:63251 {
  code: 'P2022',
  clientVersion: '5.9.1',
  meta: { modelName: 'EventChart', column: 'EventChart.å\x8F\x82å\x8A' }
}

route.ts file:

import { NextResponse } from "next/server"
import { main } from "../route"
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient

export const GET = async (req: Request, res: NextResponse ) => {
    try {
      await main()
      const eventData = await prisma.eventChart.findMany({
        select: {
          date: true,
          userId: true,
          actual: true,
          expected: true,
        }
      })
      return NextResponse.json({ message: "Success", eventData }, {status: 200})
    } catch (err) {
      console.error('Error in GET method:', err);
      return NextResponse.json({ message: "Error", err }, {status: 500})
    } finally {
      await prisma.$disconnect()
    }
  }

schema.prisma:

// 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  = "postgresql"
  url       = env("DATABASE_URL")
  directUrl = env("DIRECT_DATABASE_URL")
}

model User {
  id          Int @id @default(autoincrement())
  username    String @unique
  password    String
  email       String
  fees        Fee?
  eventChart  EventChart[]
  eventAreaChart  EventAreaChart[]
  memberChart MemberChart[]
  task        Task[]
  event       Event[]
}

model Fee {
  id          Int @id @default(autoincrement())
  userId      Int @unique
  inputFee    Int
  inputPeople Int
  feeResult   Int
  user        User @relation(fields: [userId], references: [id])
}

model EventChart {
  id       Int @id @default(autoincrement())
  userId   Int
  date     String
  expected Int
  actual   Int
  user     User @relation(fields: [userId], references: [id])
}

model MemberChart {
  id        Int @id @default(autoincrement())
  userId    Int
  year      Int
  member    Int
  user      User @relation(fields: [userId], references: [id])
}

model Task {
  id          Int @id @default(autoincrement())
  userId      Int
  date        String
  description String
  check       Boolean
  user        User @relation(fields: [userId], references: [id])
}

model Event {
  id          Int @id @default(autoincrement())
  userId      Int
  date        String
  title       String
  description String
  people      String
  fee         String
  place       String
  user        User @relation(fields: [userId], references: [id])
}

where I'm trying to fetch the data:

"use client"
import { useState, useEffect } from 'react';
import EventEditBtn from './EventEditBtn';

async function fetchEventData() {

    try {
        const res = await fetch(`http://localhost:3001/api/eventChart`, {
        cache: "no-store"
        })

        const data = await res.json()
        console.log(data)

        return data.eventData
    } catch (err) {
        console.error('Error fetching data:', err);
    }
}

const EventAreaChart = () => {

    interface eventDataType {
        id: number,
        userId: number,
        date: string
        expected: number
        actual: number
    }

    useEffect(() => {

        const fetchData = async () => {
            try {
                const data = await fetchEventData()
                setEventData(data)
                console.log(data)
            } catch (error) {
                console.error(error)
            }
        }

        fetchData()

    }, [])

  return (
    <div className="">
        
    </div>
  )
}

export default EventAreaChart

What I tried:

・When I comment out the actual column and expected column, the get method works successfully.

import { NextResponse } from "next/server"
import { main } from "../route"
import { PrismaClient } from "@prisma/client"

const prisma = new PrismaClient

export const GET = async (req: Request, res: NextResponse ) => {
    try {
      await main()
      const eventData = await prisma.eventChart.findMany({
        select: {
          date: true,
          userId: true,
          // actual: true,
          // expected: true,
        }
      })
      return NextResponse.json({ message: "Success", eventData }, {status: 200})
    } catch (err) {
      console.error('Error in GET method:', err);
      return NextResponse.json({ message: "Error", err }, {status: 500})
    } finally {
      await prisma.$disconnect()
    }
  }

・Renamed the 2 columns that weren't working. Followed this prisma's document. I was able to solve the same error which happened to MemberChart model, so I tried the same solution but didn't work this time.

I've been working on this for a week but nothing is improving anymore so please help me out.


Solution

  • I was able to fix this error by using the latest version of prisma(5.10.1).