Error with migration after removing a column

I recently deleted a column in our User table and ran the following two commands:

yarn rw prisma migrate dev
yarn rw g sdl user --force

All seemed to be going well, until I tried to insert a new user, and it would through an error telling me the field that I had deleted was missing. So in VSCode I searched the entire project and found no place in the code where this deleted field was referenced.

After a couple hours of digging, I finally found the issue

  1. The search in VSCode does not search the node_modules directory
  2. In the node_modules directory there is a .prisma directory that contains what I assume is a cache copy of the prisma.schema. When I opened this one up, it had an old version in it that still contained the deleted column
  3. I deleted the .prisma directory and re ran the migration and everything is back to working.

I’m not sure if this is a bug in the prisma migrate function or if I didn’t pass some option to it.

I’m using Redwood 6.1.0. I did not do the migration to Prisma 5 so I’m still using Prisma 4.

That’s the expected behavior for Prisma:

By default, Prisma Client is generated into the node_modules/.prisma/client folder, but you can specify a custom location

You can change it in your api/prisma/schema.prisma file, maybe to the .redwood folder:

...
generator client {
  provider = "prisma-client-js"
  binaryTargets = "native"
  output = "./.redwood"
}
...

And add it to your .gitignore.

In my dev cycle I use yarn rw prisma db push while making small changes, then do the migrate dev part when it’s ready to commit. This seems to work better in my experience.

The issue is the prisma client, the stuff in node_modules, needs to get refreshed. You can do this manually by running yarn rw prisma generate if you want, though db push will run it as well.

I’m not sure why migrate dev would have an issue here, but I don’t use it as part of my development cycle.

Thanks!

Thanks for the hint. This is the first time I’ve used Prisma. (Old dog, new trick :smile: )