Problem with generating Entity from Prisma Model.
Hello, I am new to wasp.
I add new model to Prisma
model Rocket {
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
}
Then i run the wasp db migrate-dev
I open the db studio and the Rocket is there.
Now i want to do a query
query getRockets {
// Specifies where the implementation for the query function is.
// The path
@src/queries
resolves to src/queries.js
.
// No need to specify an extension.
fn: import { getRockets } from "@src/queries",
// Tell Wasp that this query reads from the Task
entity. Wasp will
// automatically update the results of this query when tasks are modified.
entities: [Rocket]
}
And the application fails on Rocket "
.....my-project/app/main.wasp @ 346:14-19
Type error:
Undefined identifier: Rocket
"
I think the migrate does not generate the entity for me, how can i solve this?
I tried on multiple projects.3 Replies
Hi @etfarmer. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
It seems like you've defined a new model in Prisma, but you haven't defined a corresponding Entity in Wasp. In Wasp, each Entity corresponds 1-to-1 to Prisma's data model. So, you need to define an Entity in your
.wasp
file that corresponds to your Prisma model.
Here's how you can define an Entity for your Rocket
model:
After defining the Entity, you need to run wasp db migrate-dev
again to sync the database model with the Entity definitions in your .wasp
file. This command creates migration scripts and updates the database schema to include the new Entity.
Now, you should be able to use the Rocket
Entity in your query:
For more information, you can refer to the Wasp documentation on Entities (https://wasp-lang.dev/docs/data-model/entities#defining-an-entity) and Queries (https://wasp-lang.dev/docs/data-model/operations/queries#using-entities-in-queries).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @etfarmer, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?When i add the entity to the wasp file i have this error now
my-project/app/main.wasp @ 349:1 - 353:5
Validation error:
Entities can no longer be defined in the .wasp file. You should migrate your entities to the schema.prisma file. Read more: https://wasp-lang.dev/docs/migrate-from-0-13-to-0-14#migrate-to-the-new-schemaprisma-file
348 |
349 | entity Rocket {=psl
350 | id Int @id @default(autoincrement())
351 | description String
352 | isDone Boolean @default(false)
353 | psl=} I think that the model aproach is correct, I am not adding the entity into wasp file, just model to prisma schema. But the entity is not generated when i do the db migrate đź‘Ť I found the solution.. There is a different schema.prisma file. My bad.
350 | id Int @id @default(autoincrement())
351 | description String
352 | isDone Boolean @default(false)
353 | psl=} I think that the model aproach is correct, I am not adding the entity into wasp file, just model to prisma schema. But the entity is not generated when i do the db migrate đź‘Ť I found the solution.. There is a different schema.prisma file. My bad.
Ah yes, in 0.14 we moved entities out of the file into the prisma.schema file! No worries