Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

If you have access to phpMyAdmin, you should have all the tools necessary to specify foreign key constraints (migrations aren't required for that). Not doing so is ill-advised, since foreign keys ensure the consistency of your data. Using them, you can guarantee that all comments refer to a legitimate post at all times.

Make sure both tables use the InnoDB engine, add a post_id column to the comments table, define a foreign key relationship, and consider how you want updates and deletes to be handled (cascade, restrict, etc).

I didn't answer your original question of "Will Eloquent handle relationships without foreign keys defined?" because you shouldn't proceed down that path. I would suggest learning how to define foreign keys in phpMyAdmin. If there's a lot of existing data with inconsistencies that prevent you from defining foreign keys, spend time cleaning it up first.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

JeffreyR jeffreyr Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.