question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`prisma db push` Error - "Database error: Error querying the database: db error: ERROR: type "citext" does not exist" but citext extension enabled

See original GitHub issue

Bug description

https://github.com/prisma/prisma/issues/5772 - Similar issue to what is described here.

We are trying to run the prisma commands on Vercel and we keep getting this error.

Our initial migration creates the extensions as suggested above.

CREATE EXTENSION IF NOT EXISTS citext;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Weirdly, it works absolutely fine locally right now which makes it even harder to debug. The sequence of commands we are running is:

npx prisma migrate reset --force

npx prisma db push --preview-feature

To clarify, the first migration applies fine and then the second command errors. It might be worth noting that we are running against a custom postgres schema so maybe something going on in the shadow db there?

How to reproduce

Steps to reproduce the behavior:

  1. Reset your db with an initial migration to create the required extensions
  2. Run db push to apply the rest of the schema
  3. See error

Expected behavior

db push after the initial migration has been applied should already know about citext has it has been applied before.

Prisma information

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Member {
  id                 String               @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
  createTime         DateTime             @default(dbgenerated("now()"))
  externalId         String?              @unique @db.VarChar(255)
  firstName          String               @db.VarChar(255)
  lastName           String               @db.VarChar(255)
  email              String               @unique @db.Citext
  hashedPassword     String?              @db.VarChar(255)
  workTypes          String[]             @db.VarChar(64)
  useTypes           String[]             @db.VarChar(64)
}

Environment & setup

Currently happening on Vercel

  • Database: PostgreSQL
  • Node.js version: 14
  • Prisma version: 2.21.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
halvorscommented, Jul 26, 2021

have there been any progress on this?

1reaction
pimeyscommented, May 14, 2021

I think you’re right. We execute the extensions only to the shadow database, not at all to the actual one.

Plan:

  • Use the describer to describe all extensions: SELECT * FROM pg_extension
  • In the differ, find missing extensions from the actual database. Create them.

I’m still not sure would it be a problem for us when we don’t have the extensions in the PSL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

db error: ERROR: type "citext" does not exist" but ... - GitHub
Create a DB via psql and run CREATE EXTENSION citext; on the DB. Ensure your prisma folder has no migrations folder (so you're...
Read more >
Postgresql: ERROR: type "citext" does not exist - Stack Overflow
I have several databases and CREATE EXTENSION citext has to be run for each db to install the extension in that DB. You...
Read more >
Prisma schema API (Reference)
In this example, the target database is located in a file called dev.db : ... Note that the xml and citext types supported...
Read more >
Supporting features without a PSL equivalent - Prisma
How to support database features that do not have an equivalent syntax in Prisma ... querying the database: db error: ERROR: type "pgcrypto"...
Read more >
Enable PostgreSQL extensions for native database functions
Prisma Migrate creates and deletes the shadow database automatically, so the only way to activate an extension is to include it in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found