foregin ke relation and php artisan migrate

  laravel

this is my migration file for exeperts table:

 Schema::create('exeperts', function (Blueprint $table) {
            $table->increments('id');

            $table->integer('user_id')->unsigned();//fk (users)
            $table->foreign('user_id')
            ->references('id')
            ->on('users')
            ->OnDelete('cascade')
            ->onUpdate('cascade');

            $table->integer('spe_id')->unsigned(); //fk (specfaction)
            $table->foreign('spe_id')
            ->references('id')
            ->on('specfactions')
            ->OnDelete('cascade')
            ->onUpdate('cascade');

            $table->string('exp_name');
            $table->integer('exp_start');
            $table->integer('exp_end');
            $table->text('description');
            


            $table->timestamps();

when I try to migrate it, I have this error:

[IlluminateDatabaseQueryException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `job_sudan`.`exeper
  ts` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter
   table `exeperts` add constraint `exeperts_spe_id_foreign` foreign key (`sp
  e_id`) references `specfactions` (`id`) on update cascade)



  [PDOException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `job_sudan`.`exeper
  ts` (errno: 150 "Foreign key constraint is incorrectly formed")

Source: Laravel

Leave a Reply