Next.js Discord

Discord Forum

Prisma Count Issue: Different Results in Local vs. Production

Unanswered
Gharial posted this in #help-forum
Open in Discord
GharialOP
I'm using Prisma with Neon DB (free tier). I have a waitlist feature where I count the number of signups using prisma.waitlist.count(). Locally, it returns 50 (in DB there are 50 fields), but in production, it returns 36.

This is the route.js for count-api:
import { NextResponse } from "next/server";
import { prisma } from "../../../../utils/prisma";

export async function GET() {
  try {
    const count = await prisma.waitlist.count();
    return NextResponse.json({ count }, { status: 200 });
  } catch (error) {
    return NextResponse.json(
      { message: "Error fetching count" },
      { status: 500 }
    );
  }
}

77 Replies

GharialOP
if this helps:
This is my /utils/prisma.js:
import { PrismaClient } from "@prisma/client";
export const prisma = new PrismaClient();
Dwarf Hotot
are you getting some errors at prod
GharialOP
no nothing
Dwarf Hotot
maybe at console or terminal
GharialOP
got this response from API:
{"count":36}
i have same DB πŸ™‚
is it some caching issue or something?
Dwarf Hotot
can you share your prod link
@Dwarf Hotot can you share your prod link
GharialOP
can i DM?
was just in middle of something.
or wait..
can i share a " Preview Deployment" vercel link?
Dwarf Hotot
yep, whatever have problem
where should i look
GharialOP
in herosection
there's a count
of total signups
in DB there are more than 50 rows....
I am gettign only 36 from the API
Dwarf Hotot
it shows 136 πŸ˜„
@Dwarf Hotot it shows 136 πŸ˜„
GharialOP
I am starting from 100 😊😁
@Dwarf Hotot it shows 136 πŸ˜„
GharialOP
...
@Gharial I am starting from 100 😊😁
Dwarf Hotot
is it same when you query db directly
maybe there are some invalid rows
GharialOP
locally....i get the API response as count: 56
@Dwarf Hotot maybe there are some invalid rows
GharialOP
what..how?
i am doing exaclty same...for both prod n local
according to you, what qualifies as an invalid row?
Dwarf Hotot
a row with a empty or not valid input
id: 1 | "1"
GharialOP
// waitlist schema
model Waitlist {
id String @id @default(cuid())
email String @unique
createdAt DateTime @default(now())
}
only 3 fields....any of them can't be null or empty
Dwarf Hotot
but its not saying cant be null
GharialOP
i mean..i am just sending "email" to database when a user fills the form, and 'id' and 'createdAt' are filled automatically...
how can they be invalid
and if they are invalid...why is it working locally
Dwarf Hotot
can you fill database directly by your hand and deploy again
at your scheme there is no field says a field cant be null
all are nullable and dont have default when its empty
but...in DB, i dont see any empty fields
all are with correct time stamps
same format...
am i making sense?
Dwarf Hotot
okay pls try to fill db manually with 1 record and try again
@Dwarf Hotot all are nullable and dont have default when its empty
GharialOP
sorry sir....but...

model Waitlist {
  id        String   @id @default(cuid())
  email     String   @unique
  createdAt DateTime @default(now())
}


for id and createdAt i am providing a defualt value....
So these fields are not nullable and will always have a value.
@Anay-208 sorry for the ping...
In prod, what happens if we try to get all items and console log?
Dwarf Hotot
id string unique not null
@Anay-208 In prod, what happens if we try to get all items and console log?
GharialOP
srry...was about to try this..i should have tested it before posting here..mb
dw, Let me know when you try
Dwarf Hotot
i just wanted one thing from you and
@Anay-208 dw, Let me know when you try
GharialOP
found one thing...After I deploy, the production site shows the correct waitlist count, but any new signups don't reflect until I redeploy again to prod.
@Gharial is it some caching issue or something?
GharialOP
.?
GharialOP
14
πŸ™‚
"next": "14.2.11",
@Anay-208 it could be due to caching
GharialOP
is this of any help here:
export const dynamic = 'force-dynamic';
yes
in 14 its cached by default
you need to set it to dynamic
GharialOP
just mention it on top of my route?
@Anay-208 in 14 its cached by default
GharialOP
oh
@Gharial just mention it on top of my route?
just add it before your function
@Anay-208 just add it before your function
GharialOP
Solved! thanks
wanted to clear 2 more things...

Can i nest APIs like this to organise? (/waitlist is called to store email to DB, and /count is called to show total counts)
GharialOP
yes
cool πŸ‘
@Anay-208 yes, so the route created will be `/waitlist/count`
GharialOP
and secondly..
@Gharial just want to know if I am correct here or not
GharialOP
this..