I have searched all over with no luck and keep getting this error. I have checked both tables and all data types match and an index has been created. Any help would be appreciated! This is the statement I am using:
DB::statement(
"ALTER TABLE `customers`
ADD CONSTRAINT `customers_lang_code_foreign`
FOREIGN KEY (`lang_code`)
REFERENCES `languages` (`iso_code`)
ON DELETE RESTRICT
ON UPDATE CASCADE;"
);
Edit: these are all the error I get:
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: ALTER TABLE `customers`
ADD CONSTRAINT `customers_lang_code_foreign`
FOREIGN KEY (`lang_code`)
REFERENCES `languages` (`iso_code`)
ON DELETE RESTRICT
ON UPDATE CASCADE;)
at /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
/home/vagrant/code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:119
2 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint")
/home/vagrant/code/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:117
Please use the argument -v to see more details.