W
Wasp4mo ago
God

problems with entities

Wasp Version: 0.16.0 Platform: WSL2 (Linux 5.15.167.4-microsoft-standard-WSL2) I'm adding a new Vendor entity to my existing project and encountering compilation errors and migration issues: Error 1 - Compilation: server/_types/taggedEntities.ts(31,8): error TS2305: Module '"wasp/entities"' has no exported member 'Vendor' Error 2 - Migration reverting changes: During wasp db migrate-dev, it reverts my Vendor table back to an old VendorWedding table: [Db] [-] Removed tables [Db] - Vendor [Db] [+] Added tables[Db] - VendorWedding [Db] [*] Changed the Invoice table [Db] [-] Removed column vendorId My current setup: - Vendor model properly defined in schema.prisma: ```prisma model Vendor { id String @id @default(cuid()) name String category String contactInfo String? notes String? wedding Wedding @relation(fields: [weddingId], references: [id], onDelete: Cascade) weddingId String invoices Invoice[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([weddingId]) } - Operations in main.wasp (tried both with and without entities declarations): query listVendors { fn: import { listVendors } from "@src/server/vendors.ts" } - Using modern imports in server code: import { prisma } from 'wasp/server'; import type { Vendor } from '@prisma/client'; Questions: 1. How should new entities be properly defined in Wasp 0.16? 2. Why does migration revert schema changes from an existing VendorWedding migration? 3. How to resolve the taggedEntities.ts import error? 4. Is there a proper way to transition from many-to-many (VendorWedding) to one-to-many (Vendor) relationships? The generated .wasp/out/db/schema.prisma shows Vendor correctly, but compilation fails on generated files.
2 Replies
kapa.ai
kapa.ai4mo ago
Hi @God. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Here’s a focused response to your questions, based strictly on the provided knowledge sources: --- 1. How should new entities be properly defined in Wasp 0.16? In Wasp, entities are defined in your .wasp file using the Prisma Schema Language (PSL) inside {=psl ... psl=} blocks. You should not define your models directly in schema.prisma—Wasp generates this file for you based on your .wasp definitions. For example:
entity Vendor {=psl
id String @id @default(cuid())
name String
category String
contactInfo String?
notes String?
wedding Wedding @relation(fields: [weddingId], references: [id], onDelete: Cascade)
weddingId String
invoices Invoice[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([weddingId])
psl=}
entity Vendor {=psl
id String @id @default(cuid())
name String
category String
contactInfo String?
notes String?
wedding Wedding @relation(fields: [weddingId], references: [id], onDelete: Cascade)
weddingId String
invoices Invoice[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([weddingId])
psl=}
After updating your .wasp file, run wasp db migrate-dev to generate and apply the migration. Do not edit .wasp/out/db/schema.prisma directly, as it will be overwritten by Wasp during compilation and migration steps.
See: Docs > Tutorial > 4. Database Entities, Docs > Data-model > Entities --- 2. Why does migration revert schema changes from an existing VendorWedding migration? If you manually edit schema.prisma or the generated files, Wasp will overwrite those changes with what’s defined in your .wasp file. If your .wasp file still contains the old VendorWedding entity or lacks the new Vendor entity, running wasp db migrate-dev will revert to the state described in .wasp. Always update your entities in the .wasp file, not in the generated Prisma schema.
See: Docs > Data-model > Entities > Working with Entities --- 3. How to resolve the taggedEntities.ts import error? The error:
server/_types/taggedEntities.ts(31,8): error TS2305: Module '"wasp/entities"' has no exported member 'Vendor'
server/_types/taggedEntities.ts(31,8): error TS2305: Module '"wasp/entities"' has no exported member 'Vendor'
suggests that Wasp did not generate the Vendor entity type. This usually happens if the entity is not defined in your .wasp file, or if the Wasp compiler hasn’t run successfully. Make sure: - The Vendor entity is defined in your .wasp file. - You have run wasp start or wasp db migrate-dev to trigger code generation. - If you still see the error, try running wasp clean to clear the .wasp and node_modules folders, then run wasp start again to regenerate everything.
See: Discord support thread: TS2305 error on open-saas project, Discord support thread: Cannot find module 'wasp/entities' --- 4. Is there a proper way to transition from many-to-many (VendorWedding) to one-to-many (Vendor) relationships? To change your data model, update the entity definitions in your .wasp file to reflect the new relationships. For example, remove the VendorWedding entity and define the new Vendor entity as shown above. Then run wasp db migrate-dev to generate and apply the migration. Wasp/Prisma will handle the migration scripts, but you may need to manually handle data migration if you have existing data.
See: Docs > Data-model > Entities --- #### Additional Notes - Do not edit generated files in .wasp/out/db/ or schema.prisma directly. - Always define and update entities in your .wasp file. - If you encounter issues with stale or missing generated code, use wasp clean and recompile. If you follow these steps and still encounter issues, please double-check your .wasp file for correct entity definitions and ensure you’re not editing generated files directly. If problems persist, there may be a bug or edge case not covered in the current documentation. --- If you need more specific troubleshooting, please share your .wasp entity definitions and the exact steps you’re taking. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @God, 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?
toticozeni
toticozeni4mo ago
Hey @God , the kapa.ai is really wrong. 1. We use prisma under the hood so you should be fine using normal PSL inside of schema.prisma. We also use prisma for migrations, to this is more a prisma question than wasp question. 3. Entity related functions won't be properly generated in wasp unless the migration was successful. Are you still having this problem, can you give more information on the affected entities before/after migraiton. schema.prisma ? In many-to-many relationships, prisma needs to create a connecting table between to entities if one is not defined explicitly. e.g. Posts and Tags have many-to-many relationship, so it will crate _PostsToTags to connect those two. When moving back to one-to-many that table will be deleted.

Did you find this page helpful?