Hi folks! I am trying to port a very relational data model to Redwood (and thus Prisma), and I cannot get an m-n relationship to work with rw db save.
I’m new to Prisma, so it seemed likely that I was simply defining these relationship incorrectly in schema.prisma. So I decided to take an example directly from the Prisma docs and see if that fared better. Here’s what I used::
model Post {
id Int @default(autoincrement()) @id
title String
categories Category[] @relation(references: [id])
}
model Category {
id Int @default(autoincrement()) @id
name String
posts Post[] @relation(references: [id])
}
model CategoriesOnPosts {
post Post @relation(fields: [postId], references: [id])
// relation scalar field (used in the `@relation` attribute above)
postId Int
category Category @relation(fields: [categoryId], references: [id])
// relation scalar field (used in the `@relation` attribute above)
categoryId Int
createdAt DateTime @default(now())
@@id([postId, categoryId])
}
When I run yarn rw db save on this, it fails with no real information:
yarn run v1.22.4
$ /Users/crabasa/Code/fizbuz/node_modules/.bin/rw db save
Creating database migration... [started]
$ /Users/crabasa/Code/fizbuz/node_modules/.bin/prisma2 migrate save --experimental
error: No such argument.
We successfully received the error report
To help us even more, please create an issue at https://github.com/prisma/prisma2/issues/new
mentioning the report id 3258.
Thanks a lot for your help! 🙏
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Creating database migration... [failed]
→ Command failed with exit code 1: yarn prisma2 migrate save --experimental
Command failed with exit code 1: yarn prisma2 migrate save --experimental
✨ Done in 9.48s.
I created a Github issue for this, but was hoping some folks here might have an explanation or solution? Thanks!
Hey @crabasa! Sorry you’re hitting resistance right out of the gate. I did get this to work successfully on my local App.
Could you confirm which version of RedwoodJS you’re using? If you installed a fresh create-redwood-app today it would be v0.4.0. You can also use yarn rw info from your App.
Here’s what I did:
removed my existing prisma/migrations directory
removed my existing prisma/dev.db
Ran yarn rw db save on the following schema.prisma:
datasource DS {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
binaryTargets = env("BINARY_TARGET")
}
model Post {
id Int @default(autoincrement()) @id
title String
categories Category[] @relation(references: [id])
}
model Category {
id Int @default(autoincrement()) @id
name String
posts Post[] @relation(references: [id])
}
model CategoriesOnPosts {
post Post @relation(fields: [postId], references: [id])
// relation scalar field (used in the `@relation` attribute above)
postId Int
category Category @relation(fields: [categoryId], references: [id])
// relation scalar field (used in the `@relation` attribute above)
categoryId Int
createdAt DateTime @default(now())
@@id([postId, categoryId])
}
Based on feedback to my Github Issue, I created a new Prisma project using their starter app. This allowed me to test the Prisma model against their latest Beta (2.0.0-beta.2).
Both migrate save and migrate up worked under that set-up. I tested against both Sqlite and Postgres.
Got it. And thanks so much for working through this with me.
We have prisma-2.0.0-beta.2 working in Redwood master. The release holdup has been building out the generators to support Prisma’s feature updates (particularly regarding relations). But I’m also seeing some similar errors to yours reported in our GitHub Issues.
Question: by any chance do you have a globally installed version of Prisma?
Weirdly enough, I did! So I went ahead and removed it. Still no dice on the error.
Another thing I did, which was really interesting, was to run yarn rw dev, and I got a ton of error output:
➜ redwoodblog yarn rw dev
yarn run v1.22.4
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/rw dev
✖ Generating the Prisma client...
→ info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Command failed with exit code 1: yarn prisma2 generate
Error: Schema parsing
error: No such argument.
--> schema.prisma:23
|
22 | model CategoriesOnPosts {
23 | post Post @relation(fields: [postId], references: [id])
|
error: No such argument.
--> schema.prisma:26
|
25 | postId Int
26 | category Category @relation(fields: [categoryId], references: [id])
|
Validation Error Count: 2
error Command failed with exit code 1.
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/prisma2 generate
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/dev-server
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/prisma2 generate --watch
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/webpack-dev-server --config ../node_modules/@redwoodjs/core/config/webpack.development.js
08:19:02 db | Error: Schema parsing
08:19:02 db | error: No such argument.
08:19:02 db | --> schema.prisma:23
08:19:02 db | |
08:19:02 db | 22 | model CategoriesOnPosts {
08:19:02 db | 23 | post Post @relation(fields: [postId], references: [id])
08:19:02 db | |
08:19:02 db | error: No such argument.
08:19:02 db | --> schema.prisma:26
08:19:02 db | |
08:19:02 db | 25 | postId Int
08:19:02 db | 26 | category Category @relation(fields: [categoryId], references: [id])
08:19:02 db | |
08:19:02 db |
08:19:02 db | Validation Error Count: 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:03 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch exited with code 1
08:19:03 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch restarted
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/prisma2 generate --watch
08:19:03 web | ℹ 「wds」: Project is running at http://localhost:8910/
08:19:03 web | ℹ 「wds」: webpack output is served from /
08:19:03 web | ℹ 「wds」: Content not from webpack is served from /Users/crabasa/Code/redwoodblog/web
08:19:03 web | ℹ 「wds」: 404s will fallback to /index.html
08:19:03 db | Error: Schema parsing
08:19:03 db | error: No such argument.
08:19:03 db | --> schema.prisma:23
08:19:03 db | |
08:19:03 db | 22 | model CategoriesOnPosts {
08:19:03 db | 23 | post Post @relation(fields: [postId], references: [id])
08:19:03 db | |
08:19:03 db | error: No such argument.
08:19:03 db | --> schema.prisma:26
08:19:03 db | |
08:19:03 db | 25 | postId Int
08:19:03 db | 26 | category Category @relation(fields: [categoryId], references: [id])
08:19:03 db | |
08:19:03 db |
08:19:03 db | Validation Error Count: 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:03 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch exited with code 1
08:19:03 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch restarted
08:19:03 api | /Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3
08:19:03 api | throw new Error(
08:19:03 api | ^
08:19:03 api |
08:19:03 api | Error: @prisma/client did not initialize yet. Please run "prisma2 generate" and try to import it again.
08:19:03 api | In case this error is unexpected for you, please report it in https://github.com/prisma/prisma-client-js/issues/390.
08:19:03 api | at new PrismaClient (/Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3:11)
08:19:03 api | at Object.<anonymous> (/Users/crabasa/Code/redwoodblog/api/src/lib/db.js:6:19)
08:19:03 api | at Module._compile (internal/modules/cjs/loader.js:959:30)
08:19:03 api | at Module._compile (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:99:24)
08:19:03 api | at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
08:19:03 api | at Object.newLoader [as .js] (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:104:7)
08:19:03 api | at Module.load (internal/modules/cjs/loader.js:815:32)
08:19:03 api | at Function.Module._load (internal/modules/cjs/loader.js:727:14)
08:19:03 api | at Module.require (internal/modules/cjs/loader.js:852:19)
08:19:03 api | at require (internal/modules/cjs/helpers.js:74:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:03 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server exited with code 1
08:19:03 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server restarted
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/prisma2 generate --watch
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/dev-server
08:19:04 db | Error: Schema parsing
08:19:04 db | error: No such argument.
08:19:04 db | --> schema.prisma:23
08:19:04 db | |
08:19:04 db | 22 | model CategoriesOnPosts {
08:19:04 db | 23 | post Post @relation(fields: [postId], references: [id])
08:19:04 db | |
08:19:04 db | error: No such argument.
08:19:04 db | --> schema.prisma:26
08:19:04 db | |
08:19:04 db | 25 | postId Int
08:19:04 db | 26 | category Category @relation(fields: [categoryId], references: [id])
08:19:04 db | |
08:19:04 db |
08:19:04 db | Validation Error Count: 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:04 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch exited with code 1
08:19:04 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch restarted
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/prisma2 generate --watch
08:19:05 db | Error: Schema parsing
08:19:05 db | error: No such argument.
08:19:05 db | --> schema.prisma:23
08:19:05 db | |
08:19:05 db | 22 | model CategoriesOnPosts {
08:19:05 db | 23 | post Post @relation(fields: [postId], references: [id])
08:19:05 db | |
08:19:05 db | error: No such argument.
08:19:05 db | --> schema.prisma:26
08:19:05 db | |
08:19:05 db | 25 | postId Int
08:19:05 db | 26 | category Category @relation(fields: [categoryId], references: [id])
08:19:05 db | |
08:19:05 db |
08:19:05 db | Validation Error Count: 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:05 db | cd /Users/crabasa/Code/redwoodblog/api && yarn prisma2 generate --watch exited with code 1
08:19:05 api | /Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3
08:19:05 api | throw new Error(
08:19:05 api | ^
08:19:05 api |
08:19:05 api | Error: @prisma/client did not initialize yet. Please run "prisma2 generate" and try to import it again.
08:19:05 api | In case this error is unexpected for you, please report it in https://github.com/prisma/prisma-client-js/issues/390.
08:19:05 api | at new PrismaClient (/Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3:11)
08:19:05 api | at Object.<anonymous> (/Users/crabasa/Code/redwoodblog/api/src/lib/db.js:6:19)
08:19:05 api | at Module._compile (internal/modules/cjs/loader.js:959:30)
08:19:05 api | at Module._compile (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:99:24)
08:19:05 api | at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
08:19:05 api | at Object.newLoader [as .js] (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:104:7)
08:19:05 api | at Module.load (internal/modules/cjs/loader.js:815:32)
08:19:05 api | at Function.Module._load (internal/modules/cjs/loader.js:727:14)
08:19:05 api | at Module.require (internal/modules/cjs/loader.js:852:19)
08:19:05 api | at require (internal/modules/cjs/helpers.js:74:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:05 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server exited with code 1
08:19:05 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server restarted
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/dev-server
08:19:06 api | /Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3
08:19:06 api | throw new Error(
08:19:06 api | ^
08:19:06 api |
08:19:06 api | Error: @prisma/client did not initialize yet. Please run "prisma2 generate" and try to import it again.
08:19:06 api | In case this error is unexpected for you, please report it in https://github.com/prisma/prisma-client-js/issues/390.
08:19:06 api | at new PrismaClient (/Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3:11)
08:19:06 api | at Object.<anonymous> (/Users/crabasa/Code/redwoodblog/api/src/lib/db.js:6:19)
08:19:06 api | at Module._compile (internal/modules/cjs/loader.js:959:30)
08:19:06 api | at Module._compile (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:99:24)
08:19:06 api | at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
08:19:06 api | at Object.newLoader [as .js] (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:104:7)
08:19:06 api | at Module.load (internal/modules/cjs/loader.js:815:32)
08:19:06 api | at Function.Module._load (internal/modules/cjs/loader.js:727:14)
08:19:06 api | at Module.require (internal/modules/cjs/loader.js:852:19)
08:19:06 api | at require (internal/modules/cjs/helpers.js:74:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:06 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server exited with code 1
08:19:06 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server restarted
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/dev-server
08:19:07 api | /Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3
08:19:07 api | throw new Error(
08:19:07 api | ^
08:19:07 api |
08:19:07 api | Error: @prisma/client did not initialize yet. Please run "prisma2 generate" and try to import it again.
08:19:07 api | In case this error is unexpected for you, please report it in https://github.com/prisma/prisma-client-js/issues/390.
08:19:07 api | at new PrismaClient (/Users/crabasa/Code/redwoodblog/node_modules/@prisma/client/index.js:3:11)
08:19:07 api | at Object.<anonymous> (/Users/crabasa/Code/redwoodblog/api/src/lib/db.js:6:19)
08:19:07 api | at Module._compile (internal/modules/cjs/loader.js:959:30)
08:19:07 api | at Module._compile (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:99:24)
08:19:07 api | at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
08:19:07 api | at Object.newLoader [as .js] (/Users/crabasa/Code/redwoodblog/node_modules/pirates/lib/index.js:104:7)
08:19:07 api | at Module.load (internal/modules/cjs/loader.js:815:32)
08:19:07 api | at Function.Module._load (internal/modules/cjs/loader.js:727:14)
08:19:07 api | at Module.require (internal/modules/cjs/loader.js:852:19)
08:19:07 api | at require (internal/modules/cjs/helpers.js:74:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
08:19:07 api | cd /Users/crabasa/Code/redwoodblog/api && yarn dev-server exited with code 1
Even after removing the global install, it’s possible there’s something stuck in Prisma cache. I think we need to get the Beta support ready and released in order to resolve.
This isn’t exactly the same but seems relevant. I ran into a prisma-related error while setting up for local package development.
After running yarn link @redwoodjs/cli in a local app for testing, yarn rw dev fails:
yarn run v1.22.4
$ /home/dominic/projects/redwood/redwood-test/node_modules/.bin/rw dev
✖ Generating the Prisma client...
→ info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Command failed with exit code 1: yarn prisma generate
error Command "prisma" not found. Did you mean "prisma2"?
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
$ /home/dominic/projects/redwood/redwood-test/node_modules/.bin/dev-server
$ /home/dominic/projects/redwood/redwood-test/node_modules/.bin/webpack-dev-server --config ../node_modules/@redwoodjs/core/config/webpack.development.js
error Command "prisma" not found. Did you mean "prisma2"?
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
10:58:50 db | cd /home/dominic/projects/redwood/redwood-test/api && yarn prisma generate --watch exited with code 1
10:58:50 db | cd /home/dominic/projects/redwood/redwood-test/api && yarn prisma generate --watch restarted
.
.
.
error Command "prisma" not found. Did you mean "prisma2"?
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
10:58:50 db | cd /home/dominic/projects/redwood/redwood-test/api && yarn prisma generate --watch exited with code 1
10:58:51 web | ℹ 「wds」: Project is running at http://localhost:8910/
10:58:51 web | ℹ 「wds」: webpack output is served from /
10:58:51 web | ℹ 「wds」: Content not from webpack is served from /home/dominic/projects/redwood/redwood-test/web
10:58:51 web | ℹ 「wds」: 404s will fallback to /index.html
10:58:51 api | /home/dominic/projects/redwood/redwood-test/node_modules/@prisma/client/index.js:3
10:58:51 api | throw new Error(
10:58:51 api | ^
10:58:51 api |
10:58:51 api | Error: @prisma/client did not initialize yet. Please run "prisma2 generate" and try to import it again.
10:58:51 api | In case this error is unexpected for you, please report it in https://github.com/prisma/prisma-client-js/issues/390.
10:58:51 api | at new PrismaClient (/home/dominic/projects/redwood/redwood-test/node_modules/@prisma/client/index.js:3:11)
10:58:51 api | at Object.<anonymous> (/home/dominic/projects/redwood/redwood-test/api/src/lib/db.js:6:19)
10:58:51 api | at Module._compile (internal/modules/cjs/loader.js:1147:30)
10:58:51 api | at Module._compile (/home/dominic/projects/redwood/redwood-test/node_modules/pirates/lib/index.js:99:24)
10:58:51 api | at Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
10:58:51 api | at Object.newLoader [as .js] (/home/dominic/projects/redwood/redwood-test/node_modules/pirates/lib/index.js:104:7)
10:58:51 api | at Module.load (internal/modules/cjs/loader.js:996:32)
10:58:51 api | at Function.Module._load (internal/modules/cjs/loader.js:896:14)
10:58:51 api | at Module.require (internal/modules/cjs/loader.js:1036:19)
10:58:51 api | at require (internal/modules/cjs/helpers.js:72:18)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
10:58:51 api | cd /home/dominic/projects/redwood/redwood-test/api && yarn dev-server exited with code 1
10:58:51 api | cd /home/dominic/projects/redwood/redwood-test/api && yarn dev-server restarted
.
.
.
I noticed the prisma symlink in node_modules/.bin is called prisma2:
Ah, unfortunately you just stumbled into another “gotcha” setting up local development. The ‘master’ branch is already using prisma-2.0.0-beta.2. So even if you yarn link everything and then chmod -x node_modules/.bin/@redwood you will still need to locally install the prisma packages in your App. So run:
@dom This will be the case for local development anytime packages in redwoodjs/redwood are involved. We are (almost every day) complaining about the yarn link process and talking about building our own tools to improve. Something is in process, but I don’t know when it might be available.
So, to your question, if you want to update the contributing docs about how to handle packages, that would be much appreciated! Try some language to get us started and either Peter or I will help refine if/as needed.
@crabasa This is specific to local development and our CONTRIBUTING doc. I thought about mentioning this earlier, but it might just make things messier for you. ‘master’ is always in flux. For example, the Prisma package has been upgraded in master but the generator support is still in development. But, you know, you’re always welcome to try.
A few more thoughts for you:
Because you had prisma globally installed, maybe try:
Once you get prisma working at the command line, the models you have in your schema might not be compatible with our scaffold generators. You’re always able to build things manually, but that will touch on the question “wait, why am I trying Redwood again?”. You might want to kick off a new topic and include @rob for discussion about how to create your model The Redwood Way™ (To be clear, that doesn’t exist yet for this case… but it would be really helpful to the community as an example if you figured it out!) And, in any case, you’ll definitely receive a for perseverance. And definitely a
@thedavid I followed your steps from the linked Github issue, but it didn’t work. It’s seems like my schema is incompatible with the version of Prisma that you are bundling. When I run yarn prisma2 generate --schema=./api/prisma/schema.prisma manually, this is the error I get:
yarn run v1.22.4
$ /Users/crabasa/Code/redwoodblog/node_modules/.bin/prisma2 generate --schema=./api/prisma/schema.prisma
Error: Schema parsing
error: No such argument.
--> schema.prisma:23
|
22 | model CategoriesOnPosts {
23 | post Post @relation(fields: [postId], references: [id])
|
error: No such argument.
--> schema.prisma:26
|
25 | postId Int
26 | category Category @relation(fields: [categoryId], references: [id])
|
Validation Error Count: 2
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.