Laravel Eloquent – Integrity constraint violation: 1452 foreign key constraint or General error: 1005

Are¬†you trying to set-up a foreign key constraint on one of your tables and you’re getting a 1452 error?

[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

 

You might also get a General error: 1005

[PDOException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `app`.`#sql-33d4_1a2` (errno: 150 "Foreign key constraint is incorrectly formed")

 

This is a MySql issue and not a Laravel one.

Continue reading Laravel Eloquent – Integrity constraint violation: 1452 foreign key constraint or General error: 1005