php - Cannot add foreign key constraint laravel -


i have migration:

for article

public function up() {     schema::create('articles', function (blueprint $table) {         $table->engine = 'innodb';         $table->increments('id');         $table->integer('user_id')->unsigned();         $table->integer('category_id')->unsigned();         $table->string('title');         $table->string('slug')->unique();         $table->text('body');         $table->timestamps();          $table->foreign('user_id')             ->references('id')             ->on('users')             ->ondelete('cascade');          $table->foreign('category_id')             ->references('id')             ->on('categories')             ->ondelete('cascade');     }); } 

for category

public function up() {     schema::create('categories', function (blueprint $table) {         $table->increments('id');         $table->string('name');         $table->timestamps();     }); } 

when try run command php artisan migrate error:

general error: 1215 cannot add foreign key constraint (sql: alter table`articles` add constraint articles_category_id_foreign foreign key (`category_id`) references `categories` (`id`) on delete cascade) 

several times checked can not find problem.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -