Prisma "relation does not exist" (migrate before querying) in CI
Prisma passed a query to a database whose schema has no such table. In CI the almost universal cause is that migrations were not applied before the app or the test suite started querying.
What this error means
A query fails with "The table public.User does not exist in the current database." or Postgres "relation \"User\" does not exist", right after a clean database was started.
Prisma
PrismaClientKnownRequestError:
Invalid `prisma.user.findMany()` invocation:
The table `public.User` does not exist in the current database. (P2021)Common causes
Migrations never ran against the CI database
The fresh service database is empty; without a migrate step, the tables the queries expect do not exist.
Tests run before the migrate step finishes
A missing dependency ordering lets tests start before migrate deploy has created the schema.
How to fix it
Apply migrations before querying
- Run
prisma migrate deployafter the database is healthy. - Only then run the app or the test suite.
- For a fresh DB with committed migrations, deploy creates every table.
.github/workflows/ci.yml
- run: npx prisma migrate deploy
- run: npm testPush the schema for schema-only test databases
When you do not need migration history in CI, db push syncs the schema directly before tests.
Terminal
npx prisma db push --skip-generate
npm testHow to prevent it
- Always create the schema (deploy or push) before querying in CI.
- Order steps so migrations complete before tests start.
- Use a fresh database and apply committed migrations to it.
Related guides
Prisma "prisma db push" schema sync fails in CIFix "prisma db push" failures in CI - the command force-syncs schema.prisma to the database and can warn abou…
Prisma "P3005: The database schema is not empty" (baseline) in CIFix Prisma "P3005: The database schema is not empty" in CI - migrate deploy hit an existing schema with no mi…
Prisma "migrate dev" prompts and fails in CI (use migrate deploy)Fix Prisma migrate hanging or failing in CI because `migrate dev` was used - it is interactive and may reset.…