14 days 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
14 days ago
Does your code work locally?
14 days 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:
```json
"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 ."
}14 days ago
Private networking is not available during build.
14 days ago
OP won’t be able to migrate or seed.
14 days 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.
14 days 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.ts14 days ago
Did you migrate it before seeding?
14 days 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"
},14 days ago
Go to your database service in Railway and go to the database tab and check if the desired tables exist.
14 days ago
This btw. You’ll need to move migration and seed command to the pre-deploy step.
14 days ago
Yes.
14 days 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.
14 days ago
The {{}} goes in your Railway dashboard, the variables tab in your service.
14 days ago
Wait hold up.
I already have one, unless I misunderstand. My service has the private URL
14 days 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
14 days ago
Hm…
14 days ago
Okay try this
14 days ago
In your local environment, set your database URL to be your database’s public URL. (Note that this may incur some egress costs)
14 days ago
Then run npx prisma migrate status (or pnpx, depending on your pkg manager).
14 days 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
14 days ago
Try prisma migrate reset.
14 days ago
Sanity check, you’re operating on the railway database right?
14 days ago
Try prisma db push --force-reset.
14 days 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?
14 days ago
Interesting… doing dev migrate did it.
14 days ago
Did you previously have anything in prisma/migrations/ directory prior to this working?
14 days 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.
14 days ago
You should be running migrate dev before pushing to remote.
14 days ago
This will create the migration files, giving your Railway deployment something to migrate from.
14 days ago
Think that was the issue here.
14 days ago
After you ran migrate dev locally, you should be seeing some newly generated migration files in the prisma directory.
14 days ago
But good to know it’s fixed.
Also, use migrate deploy in your scripts. Don’t use dev in a prod environment.
14 days 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?
14 days ago
Think Railway needs to mark the solution for me to earn it.
Status changed to Solved noahd • 14 days ago