MIgration issue

Posted 1 year ago by juliandavidi

Hi there,

I try to create a table that is related to itself, but I have this error: Cannot add foreign key constraint, how exactly I have to created this relationship?.

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('materiales', function (Blueprint $table) {
        $table->primary('id');
        $table->integer('id');
        $table->text('nombre');
        $table->unsignedInteger('material_id')->nullable();
    });

    Schema::table('materiales', function (Blueprint $table) {
        $table->foreign('material_id')->references('id')->on('materiales');
    });
}

Thank you;

Please sign in or create an account to participate in this conversation.