Laravel 5.0 [PDOException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
<p>Good afternoon. I have a small problem on my console creating a relationship with two tables in laravel 5.0.</p>

<p>This is my product migration table:</p>

<pre><code>&lt;?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function(Blueprint $table)
        {
            $table-&gt;increments('id');
            $table-&gt;string('name', 255);
            $table-&gt;string('slug');
            $table-&gt;text('description');
            $table-&gt;string('extract', 300);
            $table-&gt;decimal('price', 8, 2);
            $table-&gt;string('quantity', 300);
            $table-&gt;string('image', 300);       
            $table-&gt;boolean('visible');
            $table-&gt;integer('category_id')-&gt;unsigned();
            $table-&gt;foreign('category_id')
                  -&gt;references('id')
                  -&gt;on('categories');
            $table-&gt;integer('brand_id')-&gt;unsigned();
            $table-&gt;foreign('brand_id')
                  -&gt;references('id')
                  -&gt;on('brands');
            $table-&gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('products');
    }

}
</code></pre>

<p>My product model:</p>

<pre><code>&lt;?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $table = 'products';

    protected $fillable = ['name', 'slug', 'description', 'extract', 'price', 'quantity', 'image', 'visible', 'category_id', 'brand_id'];


    // Relation with Category
    public function category()
    {
        return $this-&gt;belongsTo('App\Category');
    }

    // Relation with Brand
    public function brand()
    {
        return $this-&gt;belongsTo('App\Brand');
    }

    /*public function upload()
    {
        return $this-&gt;hasOne('App\Upload');
    }*/

    //Query para buscador
    public function scopeName($query, $name)
    {
        //dd("scope: " . $name);
        $query-&gt;where(\DB::raw("CONCAT(name, '', description, '', price, '', quantity)"), "LIKE", "%$name%");
    }
}
</code></pre>

<p>My category model:</p>

<pre><code>&lt;?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    protected $table = 'categories';

    protected $fillable = ['name'];

    public $timestamps = false;

    //Query para buscador
    public function scopeName($query, $name)
    {
        //dd("scope: " . $name);
        $query-&gt;where(\DB::raw("CONCAT(name)"), "LIKE", "%$name%");
    }
}
</code></pre>

<p>My brand model:</p>

<pre><code>&lt;?php 

namespace App;

use Illuminate\Database\Eloquent\Model;

class Brand extends Model
{
    protected $table = 'brands';

    protected $fillable = ['name'];

    public $timestamps = false;

    public function products()
    {
        return $this-&gt;hasMany('App\Product');
    }

    //Query para buscador
    public function scopeName($query, $name)
    {
        //dd("scope: " . $name);
        $query-&gt;where(\DB::raw("CONCAT(name)"), "LIKE", "%$name%");
    }
}
</code></pre>

<p>When I run the migration the following error message is generated:</p>

<pre><code>Migration table created successfully.



  [Illuminate\Database\QueryException]
  SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL
  : alter table `products` add constraint products_brand_id_foreign foreign k
  ey (`brand_id`) references `brands` (`id`))






  [PDOException]
  SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
</code></pre>

<p>Someone who can help me?</p>