Laravel migration can’t add foreign key

You should create column before creating a foreign key:

$table->integer('category_id')->unsigned();
$table->foreign('category_id')->references('id')->on('categories');

Documentation: http://laravel.com/docs/5.1/migrations#foreign-key-constraints

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)