unable to create foreign key in laravel.
Posted: Sun Feb 12, 2017 11:20 am
I have the following migration for my tags table:
Then i have the following migration for my admin table:
Now when i check the laravel docs the examples of foreign keys are all for primary keys:
see here https://laravel.com/docs/5.0/schema#foreign-keys
Does a foreign key always need to be a primary key ??
The tables i have created are of type "InnoDB" .. i get the following error:
http://i.imgur.com/aRaln7s.png
Thank you.
Gautam.
Code: Select all
Schema::create('tags', function (Blueprint $table) {
$table->increments('id');
// $table->mediumText('tag');
$table->char('tag' , 15);
});
Code: Select all
public function up()
{
Schema::create('admin', function (Blueprint $table) {
$table->increments('id');
$table->mediumText('title');
$table->text('blog_content');
$table->char('tag' , 15);
$table->string('filePath');
$table->string('slug');
$table->timestamps();
});
Schema::table('admin', function (Blueprint $table) {
$table->foreign('tag')->references('tag')->on('tags');
});
}
Now when i check the laravel docs the examples of foreign keys are all for primary keys:
see here https://laravel.com/docs/5.0/schema#foreign-keys
Does a foreign key always need to be a primary key ??
The tables i have created are of type "InnoDB" .. i get the following error:
http://i.imgur.com/aRaln7s.png
Thank you.
Gautam.