2
 public function up()
    {
        Schema::create('company_eligibilities', function (Blueprint $table) {
            $table->id();
            $table->string('marks');
            $table->integer('company_id')->unsigned();
            $table->timestamps();

            $table->foreign('company_id')
                ->references('id')->on('companies')
                ->onDelete('cascade')
                ->onUpdate('cascade');
        });
    }

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

Company migration already did before executing the above migration

I am getting the above error when I am trying to create a table along with the foreign key. Have I done something wrong ??

STA
  • 30,729
  • 8
  • 45
  • 59
Curious Coder
  • 33
  • 1
  • 6

1 Answers1

1

Make sure that, you migrate companies before migrate company_eligibilities, change your foreign key id to unsigned big integer, Laravel 5.8 make default foreign key as unsigned big integer, also for 6.x and 7.x :

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

Or,

$table->unsignedBigInteger('company_id');
STA
  • 30,729
  • 8
  • 45
  • 59