Framework: Error creating foreign keys in Laravel 5.8 [General error: 1005]

Created on 9 Mar 2019  路  5Comments  路  Source: laravel/framework

  • Laravel Version: 5.8.
  • PHP Version: 7.2.9
  • Database Driver & Version:
    MariaDB 10.1.38

Description:

I'm trying to do some migrations, as I used to do in previous versions. but in this version of 5.8 I have an Error.

The error is of I'm trying to place the foreign keys

Example

Categories

Cat_Favorites

I have read the official documentation and what has been done as such. I have made a new project in 5.7 and everything works perfect. but with 5.8 no, I do not know if something has changed that I'm not realizing?

PDOException::("SQLSTATE[HY000]: General error: 1005 Can't create tablethigsel.#sql-3356_2a(errno: 150 "Foreign key constraint is incorrectly formed")")

This error is not removed. but as I said if I do it in a version lower than 5.8 everything works fine.

Steps To Reproduce:

Most helpful comment

same of @antonioftamura i put the unsigned() method to work! if not doesn 麓t work for me.
Heres my code that its right:
Schema::create('places', function (Blueprint $table) { $table->BigIncrements('id');
other file:
// place_id $table->BigInteger('place_id')->unsigned(); $table->foreign('place_id')->references('id')->on('places');

Thanks!

All 5 comments

Have you seen #27717?

I miss this information.
I just had to put in the foreign key

bigInteger

exactly how

BigIncrements

In my cross-reference, I mistakenly used bigInteger. I corrected with

$table->bigInteger('cliente_id')->unsigned();

Now works!

same of @antonioftamura i put the unsigned() method to work! if not doesn 麓t work for me.
Heres my code that its right:
Schema::create('places', function (Blueprint $table) { $table->BigIncrements('id');
other file:
// place_id $table->BigInteger('place_id')->unsigned(); $table->foreign('place_id')->references('id')->on('places');

Thanks!

Check that the storage engines for each table are the same as well. If they're different, it will throw this error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

klimentLambevski picture klimentLambevski  路  3Comments

felixsanz picture felixsanz  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments

digirew picture digirew  路  3Comments

gabriellimo picture gabriellimo  路  3Comments