3 months ago
Hey, I have a React Router 7 project that uses Prisma as its ORM. However, I am completely lost at how to seed the database/run migrations. I keep getting Error: Could not find Prisma Schema that is required for this command.
66 Replies
3 months ago
Does your code work locally?
3 months ago
Did you commit your schema files?
Build command: npm run build
Start command: npm run start
"scripts": {
"build": "react-router build",
"start": "prisma migrate deploy --schema=./prisma/schema.prisma && prisma generate --schema=./prisma/schema.prisma && react-router-serve ./build/server/index.js",
"dev": "react-router dev",
"typecheck": "react-router typegen && tsc",
"format": "prettier --write ."
},
"prisma": {
"schema": "./prisma/schema.prisma",
"seed": "ts-node ./prisma/seed.ts"
},I've tried a lot of different permutations of the scripts and really am lost 😅
Hey, you should move prisma generate to the build step instead since you only need to run it when code changes.
Update your scripts:
"scripts": {
"build": "prisma generate --schema=./prisma/schema.prisma && react-router build",
"start": "prisma migrate deploy --schema=./prisma/schema.prisma && prisma db seed && react-router-serve ./build/server/index.js",
"dev": "react-router dev",
"typecheck": "react-router typegen && tsc",
"format": "prettier --write ."
}Hey, you should move prisma generate to the build step instead since you only need to run it when code changes.
Update your scripts:
"scripts": {
"build": "prisma generate --schema=./prisma/schema.prisma && react-router build",
"start": "prisma migrate deploy --schema=./prisma/schema.prisma && react-router-serve ./build/server/index.js",
"dev": "react-router dev",
"typecheck": "react-router typegen && tsc",
"format": "prettier --write ."
}3 months ago
Private networking is not available during build.
3 months ago
OP won’t be able to migrate or seed.
3 months ago
Yes, but I doubt that’ll fix the primary issue as it’s not about not being able to find your database, but rather the Prisma schema itself.
But you can give it a try.
I managed to get a different error, I'll post it in a second, but the schema has now been found which is good.
3 months ago
Oh thats good.
(No subject)
meta: {
PrismaClientKnownRequestError:
Invalid `prisma.map.create()` invocation:
modelName: 'Map',
driverAdapterError: DriverAdapterError: TableDoesNotExist
at PrismaPgAdapter.onError (file:///app/node_modules/@prisma/adapter-pg/dist/index.mjs:651:11)
The table `public.Map` does not exist in the current database.
at PrismaPgAdapter.performIO (file:///app/node_modules/@prisma/adapter-pg/dist/index.mjs:646:12)
at zr.handleRequestError (/app/node_modules/@prisma/client/src/runtime/RequestHandler.ts:237:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at zr.handleAndLogRequestError (/app/node_modules/@prisma/client/src/runtime/RequestHandler.ts:183:12)
at async PrismaPgAdapter.queryRaw (file:///app/node_modules/@prisma/adapter-pg/dist/index.mjs:566:30)
at zr.request (/app/node_modules/@prisma/client/src/runtime/RequestHandler.ts:152:12)
at async e.interpretNode (/app/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:182:26)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async a (/app/node_modules/@prisma/client/src/runtime/getPrismaClient.ts:808:24)
at async main (/app/prisma/seed.ts:2022:5) {
code: 'P2021',
at async e.interpretNode (/app/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:209:41)
at async e.interpretNode (/app/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:268:41)
at async e.run (/app/node_modules/@prisma/client-engine-runtime/src/interpreter/query-interpreter.ts:93:23)
at async e.execute (/app/node_modules/@prisma/client/src/runtime/core/engines/client/LocalExecutor.ts:81:12)
at async qt.request (/app/node_modules/@prisma/client/src/runtime/core/engines/client/ClientEngine.ts:492:22) {
cause: [Object]
}
},
clientVersion: '7.4.1'
}
An error occurred while running the seed command:
Error: Command failed with exit code 1: tsx prisma/seed.ts3 months ago
Did you migrate it before seeding?
3 months ago
Seems like it’s trying to modify a table that doesn’t exist yet.
My Pre-deploy command is npx prisma migrate deploy && npx prisma db seed
Here is the updated scripts section too (apologies for the code spam 😅)
"scripts": {
"build": "DATABASE_URL=\"postgres://placeholder:5432\" npx prisma generate && react-router build",
"start": "react-router-serve ./build/server/index.js",
"dev": "react-router dev",
"typecheck": "react-router typegen && tsc",
"format": "prettier --write ."
},
"prisma": {
"seed": "tsx ./prisma/seed.ts"
},3 months ago
Go to your database service in Railway and go to the database tab and check if the desired tables exist.
3 months ago
This btw. You’ll need to move migration and seed command to the pre-deploy step.
3 months ago
Yes.
3 months ago
In your database URL variable in the shell command, try using the provided reference variable.
Add a variable entry called DATABASE_URL in your service with the value ${{Postgres.DATABASE_URL}}, and remove the existing DATABASE_URL=… in your script.
3 months ago
The {{}} goes in your Railway dashboard, the variables tab in your service.
3 months ago
Wait hold up.
I already have one, unless I misunderstand. My service has the private URL
3 months ago
Try deleting that table. Perhaps Prisma thinks it already successfully migrated everything when it hasn’t yet.
Then redeploy the service.
Didn't see a way to delete the migration table, but I've redeployed and will see
3 months ago
Hm…
3 months ago
Okay try this
3 months ago
In your local environment, set your database URL to be your database’s public URL. (Note that this may incur some egress costs)
3 months ago
Then run npx prisma migrate status (or pnpx, depending on your pkg manager).
3 months ago
See if Prisma thinks everything has been applied.
I also get the same error as before when running the seed locally with the public url
3 months ago
Try prisma migrate reset.
3 months ago
Sanity check, you’re operating on the railway database right?
3 months ago
Try prisma db push --force-reset.
3 months ago
And check if any tables exist in your Railway dashboard.
I just ran the following:
npx prisma migrate dev
npx prisma generate
npx prisma db seed
Now all the tables have appeared! However, I'd rather have this run automatically when deploying.
Should I just move generate into the pre deploy then, as it works in this order?
3 months ago
Interesting… doing dev migrate did it.
3 months ago
Did you previously have anything in prisma/migrations/ directory prior to this working?
3 months ago
I think what you needed was to generate migration files. This was why Prisma couldn’t find the tables. Your deployment had nothing to migrate from.
3 months ago
You should be running migrate dev before pushing to remote.
3 months ago
This will create the migration files, giving your Railway deployment something to migrate from.
3 months ago
Think that was the issue here.
3 months ago
After you ran migrate dev locally, you should be seeing some newly generated migration files in the prisma directory.
3 months ago
But good to know it’s fixed.
Also, use migrate deploy in your scripts. Don’t use dev in a prod environment.
3 months ago
But yes, keep that in mind whenever you make any changes to the schema from now on.
Perfect, so whenever I make changes locally I run migrate dev and push that? Then Railway will know what to do with them. Sounds good. Really appreciate the help and your time 😊
I'm not sure how the Bounty Board works, but don't you get a reward or something for helping?
3 months ago
Think Railway needs to mark the solution for me to earn it.
Status changed to Solved noahd • 3 months ago