I have a categories table which has an id and a slug(varchar type) column.I want to create a subcategories table which will have a column category_slug(varchar type) that will reference the slug column in the Category table.
I am getting errors during php artisan migrate.
Schema::create('subcategories', function (Blueprint $table) {
$table->increments('id');
$table->string('category_slug')->unique();
$table->foreign('category_slug')
->references('slug')->on('categories');
$table->timestamps();
});
The errors in the terminal are.
[Illuminate\Database\QueryException] SQLSTATE[HY000]: General error: 1005 Can't create table
laravel_eshopper.#sql-ee8_272(errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter tabletabpanesadd constrainttabpanes_category_slug_foreignforeign key (category_slug) referencescategories(slug))[PDOException] SQLSTATE[HY000]: General error: 1005 Can't create table
laravel_eshopper.#sql-ee8_272(errno: 150 "Foreign key constraint is incorrectly formed")
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u7WrPo
via IFTTT
Aucun commentaire:
Enregistrer un commentaire