How can I create a JSON field in a model?
Hi,
I'm trying to create a model that has a JSON field (Mainly to store a structured data) but I'm facing an error that I can't figure it out.
Here are the models:
When I try to start Wasp I get the following error. If I do not create the FK between Scan and QRCode it works fine.
Thanks in advance!
9 Replies
Hi @Andres Montalban. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the provided models, it seems like you are trying to use a JSON field (
geoLocationData
) in your Scan
model. The error message is not provided, so it's hard to pinpoint the exact issue. However, Wasp uses Prisma under the hood to interact with the database, and Prisma does support JSON fields.
If you're having trouble with the JSON field, it might be due to the database you're using. Not all databases support JSON fields. For example, SQLite doesn't support JSON fields, while PostgreSQL does.
If you're using a database that supports JSON fields and you're still encountering an issue, it might be due to a Prisma-related issue. You can check the Prisma documentation (https://www.prisma.io/docs/) for more information on how to use JSON fields.
If you're still having trouble, you might want to check the Wasp community (https://discord.com/channels/686873244791210014) or Wasp Github issues (https://github.com/wasp-lang/wasp/issues) for similar problems or to ask for help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Andres Montalban, 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?@kapa.ai sorry I provided the error message. I am using PostgreSQL as backend database.
Let me check the knowledge base for you again. One moment! :books:
----------------------
I'm sorry, but without the error message, it's difficult to provide a specific solution to your problem. However, since you're using PostgreSQL, which supports JSON fields, the issue might be related to how you're using the JSON field in your code.
If you're trying to insert or update data in the JSON field, make sure you're providing a valid JSON object. If you're querying data, ensure you're using the correct Prisma methods for JSON fields.
If the issue persists, I recommend checking the Prisma documentation (https://www.prisma.io/docs/) for more information on how to use JSON fields with PostgreSQL. You can also reach out to the Wasp community (https://discord.com/channels/686873244791210014) or Wasp Github issues (https://github.com/wasp-lang/wasp/issues) for more help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Andres Montalban, 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?
@miho @sodic will be able to shed some light on this potentially.
In the meantime @Andres Montalban : where is that error coming from exactly? server/crud/QRCodes.ts -> are you using the wasp's CRUD functionality? What if you don't use Crud but instead implement your own Queries and Actions, have you given that a try maybe?
Thank you @martinsos I will give it a try to Queries and Actions and report back
Which Wasp version are you using? 🙂
I'm not sure if we support JSON fields properly in our serialisation layer @sodic
Created an issue: https://github.com/wasp-lang/wasp/issues/2348
Created an issue: https://github.com/wasp-lang/wasp/issues/2348
GitHub
Figure out if we support Prisma JSON fields · Issue #2348 · wasp-la...
We should check if our serialisation layer supports JSON fields https://ptb.discord.com/channels/686873244791210014/1296850534325686351/1296850534325686351
Yeah, we most likely don't. I never tried using them
Thanks for making the issue @miho
@Andres Montalban Any luck when switching to Queries/Actions
Hey, sorry for the delay. I ended up using an action for what I needed but had to create the DB fields that were present in the JSON in order to unblock me. Thanks!
Wohooo @Andres Montalban, you just became a Waspeteer level 1!