0

I've checked several times against other projects and I just cannot see what's wrong.

I attach my code:

        Schema::table('datos', function (Blueprint $table) {

            $table->bigInteger('sensor_id')->change();
            $table->foreign('sensor_id')->references('id')->on('sensores')->nullable();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('datos', function (Blueprint $table) {
        $table->dropForeign(['sensor_id']);
    });
}
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Esteban
  • 3
  • 2

2 Answers2

0

make sure the sensor_id is unsignedBigInteger and move nullable method before change

TEFO
  • 1,432
  • 9
  • 23
0

Your function will be look like :

public function up()
    {
        Schema::create('datos', function (Blueprint $table) {
            $table->bigIncrements('id');

            $table->bigInteger('sensor_id')->unsigned();
            $table->foreign('sensor_id')->references('id')->on('sensores')->onDelete('cascade');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('datos');
    }
STA
  • 30,729
  • 8
  • 45
  • 59