Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行php artisan migrate时出现Laravel不兼容外键错误_Php_Laravel - Fatal编程技术网

运行php artisan migrate时出现Laravel不兼容外键错误

运行php artisan migrate时出现Laravel不兼容外键错误,php,laravel,Php,Laravel,我试图在laravel迁移中创建一个外键,它引用同一个表上的一列。事情是这样的 $table->bigInteger('category_id'); $table->unsignedBigInteger('parent_id')->nullable(); $table->foreign('parent_id')->references('category_id')->on('categories')->onDelete('set null')->o

我试图在laravel迁移中创建一个外键,它引用同一个表上的一列。事情是这样的

$table->bigInteger('category_id');
$table->unsignedBigInteger('parent_id')->nullable();
$table->foreign('parent_id')->references('category_id')->on('categories')->onDelete('set null')->onUpdate('cascade');
当我运行
php-artisan-migrate:fresh
时,它返回以下错误

SQLSTATE[HY000]:一般错误:3780外键约束“categories\u parent\u id\u foreign”中引用列“parent\u id”和引用列“category\u id”不兼容。


从我在migration中所写的内容来看似乎是正确的,但不确定是什么导致了这种情况。

bigIngeger和
unsignedbiginger
不兼容

您必须使用相同的类型

只需将
biginger
替换为
unsingedBigInteger

$table->unsignedbiginger('category_id');
。。。并为您的
category\u id
字段添加索引

$table->index('category_id');

bigingeer和
unsignedbiginger
不兼容

您必须使用相同的类型

只需将
biginger
替换为
unsingedBigInteger

$table->unsignedbiginger('category_id');
。。。并为您的
category\u id
字段添加索引

$table->index('category_id');

我希望下面的代码能起作用


$table->bigIncrements('category_id');   
$table->bigInteger('parent_id')->unsigned()->nullable();

$table->foreign('parent_id')->references('category_id')->on('categories')->onDelete('set null')->onUpdate('cascade');

我希望下面的代码可以工作


$table->bigIncrements('category_id');   
$table->bigInteger('parent_id')->unsigned()->nullable();

$table->foreign('parent_id')->references('category_id')->on('categories')->onDelete('set null')->onUpdate('cascade');

category\u id
不是无符号的,类型必须完全匹配。。。我猜你不想要一个自动递增的key@lagbox现在它说它缺少一个索引,这对我来说是一个不同的问题。也许您可以用更多细节更新当前问题,或者创建一个新问题并关闭此问题。
category\u id
没有未签名,类型必须完全匹配。。。我猜你不想要一个自动递增的key@lagbox现在它说它缺少一个索引,这对我来说是一个不同的问题。也许您可以使用更多详细信息更新当前问题,或者创建一个新问题并关闭此问题。
引用表“categories”中缺少约束“categories\u parent\u id\u foreign”的索引。
newerror@Areg您使用的数据库引擎是什么?@Areg更新了答案。您需要为引用的字段添加索引。
在引用的表“categories”中缺少约束“categories\u parent\u id\u foreign”的索引。
newerror@Areg您使用的数据库引擎是什么?@Areg更新了答案。您需要为引用的字段添加索引。