Next.js Discord

Discord Forum

PrismaClientInitializationError in prisma and Next js.

Unanswered
Lilac posted this in #help-forum
Open in Discord
LilacOP
does somebody have some experience with next js and prisma? I am stuck in this error and I don't know how to get around it.
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";
import { authOptions } from "../auth/[...nextauth]/route";
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

export async function POST(req: NextRequest) {
  const session = await getServerSession(authOptions);
  if (!session) {
    return NextResponse.redirect("http://localhost:3000/api/auth/signin");
  }
  const body = await req.json();
  try {
    const post = await prisma.post.create({
      data: {
        title: body.title,
        content: body.content,
        image: body.image,
        email: session?.user?.email,
      },
    });
  } catch (error) {
    return NextResponse.json({ message: error }, { status: 400 });
  }

  return NextResponse.json(
    { message: "Successfully posted your blog" },
    { status: 200 }
  );
}

And this is the error i am getting when making a api call to this.
{
    "message": {
        "name": "PrismaClientInitializationError",
        "clientVersion": "4.16.2"
    }
}

I have used prisma generate and prisma db push still getting this
model Post {
  id        Int       @id @default(autoincrement())
  title     String
  content   String?
  published Boolean   @default(false)
  image     String?
  email     String
  date      DateTime  @default(now())
}
This is how my model look like

0 Replies