Migration creates Implicit relational tables in database for an explicit M-N relationship
I have created two models, Parameters and Tests. Also, there is a model that defines explicit M-N relationship between these models.
When I migrate the schema to database, it is also creating a table "_ParameterToTest" in the database, that is usually created for implicit relationship. How do I avoid creating this database?
Solution:Jump to solution
Hi @Faiz Khatri π
In your schema, you have defined an explicit many-to-many relationship using the
ParametersToTests
model. However, you've also defined an implicit many-to-many relationship by including Parameters Parameter[]
in the Test model and Tests Test[]
in the Parameter model.
To avoid creating the additional _ParameterToTest
table, you need to remove these implicit relation fields and rely solely on your explicit relationship through the ParametersToTests model. ...3 Replies
Solution
Hi @Faiz Khatri π
In your schema, you have defined an explicit many-to-many relationship using the
ParametersToTests
model. However, you've also defined an implicit many-to-many relationship by including Parameters Parameter[]
in the Test model and Tests Test[]
in the Parameter model.
To avoid creating the additional _ParameterToTest
table, you need to remove these implicit relation fields and rely solely on your explicit relationship through the ParametersToTests model.
Something like this should work
ohh... That was a horrible mistake... didn't even think about checking the models while reading documentation πΆβπ«οΈ
Thank you so much @Nurul (Prisma)
No worries! Happy to help! π