Tutorial - deployment issues with db

I just completed the tutorial (1), all went well locally so I deployed to Netlify.

In the tutorial under Deployment at the top it says you need to change schema.prisma to update the provider - provider = "postgresql".

No problem, but it doesn’t say anything else like we need to do rw prisma migrate dev. So I committed and pushed to my repo, and now in the Netlify build log I get an error:

3:54:58 PM: Running Prisma CLI:
3:54:58 PM: yarn prisma migrate deploy --schema "/opt/build/repo/api/db/schema.prisma"
3:54:58 PM: Prisma schema loaded from db/schema.prisma
3:54:58 PM: Datasource "db": PostgreSQL database "railway", schema "public" at "containers-us-west-1.railway.app:6115"
3:54:59 PM: Error: P3014
3:54:59 PM: 
3:54:59 PM: The datasource provider `postgresql` specified in your schema does not match the one specified in the migration_lock.toml, `sqlite`. Please remove your current migration directory and start a new migration history with prisma migrate dev. Read more: https://pris.ly/d/migrate-provider-switch
3:54:59 PM: error Command failed with exit code 1.

The site is there but there is an error:
Error: Invalid prisma.post.findMany()invocation: The tablepublic.Post does not exist in the current database.

Inside the migration_lock file it does still say sqlite - and also has a comment to not edit the file manually.

Locally I tried running rw prisma migrate dev but it errors now:


Error: Schema Parsing P1012
Get config 
  -->  schema.prisma:3
   | 
 2 |   provider = "postgresql"
 3 |   url      = env("DATABASE_URL")

Validation Error Count: 1

error Command failed with exit code 1.

which of course now I am using postgresql not sqlite any more, and I don’t have postgres locally. Maybe I should add the url to the railway db in a local env file?

Prisma support says to delete the migrations folder and run prisma migrate dev.

Not sure what to do now, any help appreciated.

when I switched to postgresql I had to delete the lockfile & then rerun the rw prisma generate

(also, I had to prefix the DATABASE_URL with postgresql, not merely postgre)

cheers!

Ok I have it working now:

  • deleted the Migrations folder
  • created an .env file with the url to the live db on railway
  • ran yarn rw prisma migrate dev again
  • committed and pushed the repo

the netlify log then showed an error saying it timed out trying to connect to railway, but when I go to the site it is all working.

Seemed like there was a step or 2 missing from the tutorial about this, but it works! other than the tutorial was very helpful.

1 Like