php - 外键约束不兼容?
问题描述
在重新处理一些表逻辑后试图让我的迁移工作,但我在迁移时遇到了问题。与约束冲突有关。
运行php artisan migrate:fresh
时显示这个,
In Connection.php line 665:
SQLSTATE[HY000]: General error: 3780 Referencing column 'cache_id' and referenced column 'id' in
foreign key constraint 'cache_connections_cache_id_foreign' are incompatible. (SQL: alter table
`cache_connections` add constraint `cache_connections_cache_id_foreign` foreign key (`cache_id`
) references `cache` (`id`))
In Connection.php line 459:
SQLSTATE[HY000]: General error: 3780 Referencing column 'cache_id' and referenced column 'id' in
foreign key constraint 'cache_connections_cache_id_foreign' are incompatible.
迁移:
Schema::create('cache', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('item')->unique();
$table->string('name');
$table->string('picture');
$table->string('description');
$table->unsignedInteger('connection_count');
$table->boolean('is_private');
$table->json('additional_data')->nullable();
$table->string('type_id');
$table->timestamps();
});
Schema::create('cache_connections', function (Blueprint $table) {
$table->bigInteger('cache_id');
$table->string('connection');
$table->timestamps();
$table->foreign('cache_id')
->references('id')
->on('cache')
;
});
解决方案
这可能是由于bigIncrements()
使用unsignedBigInteger()
,而不是bigInteger()
。尝试更新您的cache_connections
迁移以使用未签名的方法。
供应商/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php
/**
* Create a new auto-incrementing big integer (8-byte) column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function bigIncrements($column)
{
return $this->unsignedBigInteger($column, true);
}
推荐阅读
- node.js - 在 nodeJS 服务器上正确保存 JSON 数据
- html - 你如何在css中调整背景图像的大小?
- c++ - C ++如何打印矢量
, 向量 > > 维帕 - flutter - 如何在 Flutter 中使用带有自定义标签的 ChoiceChip 创建包装
- sql - 如何在 SQL 中使用 STUFF 和 UPDATE
- reactjs - 在 React 和 TypeScript 中使用 DRY 变化句柄形成表单
- javascript - [^)] 在这个正则表达式 / *\([^)]*\) */g 中做了什么
- javascript - 尽管内部控制台日志显示该值,但该函数返回未定义
- python - 浮动画布上光标的坐标
- f# - 如何在 F# 中重定向标准和错误输出