@mhballa It seems table ordering has issue!
Maybe you can use php artisan migrate:fresh, it will recreate tables in the correct order.
I have been following 30 day to learn laravel , I am on ep 12 Pivot Tables and BelongsToMany Relationships
in this lesson we are building a Pivot Table between a Job table and a Tag table. build the Pivot table no problem, we populate the table. then deleting the entry in the job table to see the orphan in the pivot table, then add constraint in the tags table migration to cascade the delete, everything up to here is working. when migrate rollback and migrate to update the tables with constraint I get this Query Exception:
SQLSTATE[HY000]: General error: 1824 Failed to open the referenced table 'job_listings' (Connection: mysql, SQL: alter table job_tag add constraint job_tag_job_listing_id_foreign foreign key (job_listing_id) references job_listings (id) on delete cascade)
I have been using MySQL instead of SQLite for this course.
is there a different between MySQL and SQLite for pivot table and constraints ?
is this the cause? or something in the code?
Edit: I removed the constrained cascade On Delete from the tags table migration, and migration work but when i add the constrained , the error appear. is there a problem in MySQL and constrained. because in the video he use SQLite , and i use MySQL ?
SOLVED
First: make sure your table name is matching , look for misspelling and error , double , triple checks
Second: MySQL is very strict about Migration Order , make sure that the time stamp of the migration something like -> 2025_05_10_100737 for the linked table is before the pivot table migration because if pivot table is before , MySQL will through error. change the timestamp to earlier time like 2025_05_09_100737 before the time stamp of the pivot table migration.
Please or to participate in this conversation.