prisma db pull doesn't see a new table

Viewed 838

I have existing schema for prisma. I copied the table from another schema to be included in the Prisma schema. But when I run prisma db pull new table doesn't appear in Prisma schema. Why?

3 Answers

You're misinterpreting the function of the prisma db pull command.

From the docs

The db pull command connects to your database and adds Prisma models to your Prisma schema that reflect the current database schema.

Basically, it will make your Prisma schema match the existing database schema. What you want is the opposite here: Update the database schema to match the current Prisma schema.

You can do this in two ways:

  1. If you want to update the database and keep the changes in your migration history, use the prisma migrate dev command. More Info

  2. If you just want to update the database without creating a migration, use the prisma db push command. More info

More information is available in the docs explaining how you should choose between 1 and 2.

I had a similar issue once and a quick check confirmed for me that it was the lack of security permissions granted for prisma on new table in the database itself.

Try this:

  • Note the name of the database user that Prisma connects to the database with. You'll likely find this via your schema.prisma file, or perhaps via a DATABASE_URL config setting in the related .env file if you're using that with prisma.
  • Go into the database itself and ensure that database user which Prisma connects with has been granted sufficient security privileges to that new table. (note: what 'sufficient' is I cannot say since it depends on your own needs. At a guess, I'd say at least 'select' permission would be needed.)
  • Once you've ensure that user has sufficient privileges, try running a prisma db pull command once again.

For reference, another thing you could do is:

  • cross-check against one of the other tables that is already in your database that works correctly with prisma.
  • compare the security privileges of that old table with the security privileges of the new table and see if there are any differences.

If you use supabase and running this command and it returns something like this 'The following models were commented out because we couldn't retrieve columns for them. Please check your privileges.' or something similar regarding privileges, the solution is to go to your SQL editor from supabase and put this command and execute it

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO postgres;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO postgres;
Related