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:
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 ??
Try
$table->foreign('tag')->references('id')->on('tags');
Because in tags
table, the primary key is id
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.