laravel - 1215 Impossible d'ajouter des contraintes d'index externe
问题描述
i want to create foreign table and product table keys but it gives me error. 1215 Unable to add external index constraints
(SQL: alter table `category_product` add constraint` category
_product_category_id_foreign` foreign key (`category_id`) references` category` (`id`) on delete cascade)
i don't know where exactly is the error.
products table
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('slug')->unique();
$table->string('details')->nullable();
$table->integer('price');
$table->string('description');
$table->timestamps();
});
categories table
Schema::create('categories', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('slug')->unique();
$table->timestamps();
});
category_product table
Schema::create('category_product', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('product_id')->unsigned()->nullable();
$table->foreign('product_id')->references('id')
->on('products')->onDelete('cascade');
$table->integer('category_id')->unsigned()->nullable();
$table->foreign('category_id')->references('id')
->on('category')->onDelete('cascade');
$table->timestamps();
});
解决方案
推荐阅读
- ffmpeg - 我可以在生成的 ffmpeg 视频上测试 nvidia 解码器(nvdec/cuvid)的功能吗?
- swift - 使用自定义 segue 时出现 Swift 约束问题
- c++ - Getting several WM_PAINT message with one dispatch
- html - iframe 中的链接正常,但不显示在嵌入页面中
- spring-boot - 未找到 Spring Boot 执行器运行状况检查
- pandas - Pyspark Dataframe udf 依赖于先前的索引值
- mysql - 不在分组日期中的 SQL 连接
- node.js - Google Photos API - 有没有办法提取评论
- python - 获取表格单元格的内容而不删除里面的标签
- sql-server - Opentext 内容服务器无法创建/连接到数据库