0

I have a migration for my tags table like the below:

Schema::create('tags', function (Blueprint $table) {
            $table->increments('id');
            $table->char('tag' , 15);
});

Now, I have the following migration for my admin table in which i have a foreign key associated with my tags table , the migration is the following:

Schema::create('admin', function (Blueprint $table) {
    $table->char('tag' , 15);
    $table->foreign('tag')->references('tag')->on('tags');
});

Now when i run this migration i get the following error:

enter image description here

Both the tables are innodb i have changed this in the settings in laravel. But i still get a cannot add a foreign key constraint error. Why ??

Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174

1 Answers1

0

Try

$table->foreign('tag')->references('id')->on('tags');

Because in tags table, the primary key is id.

EddyTheDove
  • 12,979
  • 2
  • 37
  • 45