Studio not enough info to infer relation
I'm getting this error:
Here's my schema:
https://github.com/budivoogt/bv_markdown_blog/blob/a15ec5062337460647693dd070e504e9eca54e14/src/lib/schemas/drizzleSchema.ts
I believe I followed the docs carefully and ensured every table has its relations defined. The app works fine but studio doesn't launch. Any suggestions?
GitHub
bv_markdown_blog/src/lib/schemas/drizzleSchema.ts at a15ec506233746...
Personal blog with Markdown posts hosted in external database. Supabase for Postgres, Auth, Storage with Drizzle ORM, Shadcn-Svelte, Tailwind CSS. - budivoogt/bv_markdown_blog
12 Replies
postRelations
should use tagsToPosts
not tags
That fixed it! Good eye.
And the reason why is because the
tags
table isn't related to posts directly, so I have to use the tagsToPosts
table which defines those relationships?Yep. Tables are linked by reference.
is an intermediate table necessary in this instance?
For many-to-many relationships, yes
Ah ok, I was trying to do something like this, need an intermediate I guess. Althoo I don't think you really should 🤔
Could be good to make this a bit more clear in the error message, see there is a lot of recent posts in this channel about this specific error message
(sorry for hijacking this thread)
I didn't think my specific example was a many-to-many situation though
it's one to many right?
1 chat -> many messages
Oh, one-to-many does not need an intermediate table. Only needs an id on the many side. In your case, it would be a chatId on the message table.
And you don't need a
relationName
unless you have multiple relations between the same two tables.oh I see, thanks, that's what I initially thought
not too sure why mine is not working, seems like a bug
Your chat-message relations look fine to me
yea me too.. I've spent ages debugging. Gonna try dig into the drizzle src and see what might be causing it
99.9% sure there's nothing wrong with my definitions tho