【发布时间】:2021-06-09 02:59:48
【问题描述】:
这是我的数据库和migration.php
我想将category_id 设置为foreign key 但发生不兼容错误。
我不知道为什么它不兼容。我该如何解决?
mysql> desc category;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(256) | YES | | NULL | |
| type | char(1) | YES | | NULL | |
| order | int | YES | | NULL | |
public function up()
{
Schema::create('peaces', function (Blueprint $table) {
$table->bigIncrements('id')->unique();
$table->bigInteger('category_id')->unsigned();
$table->Integer('price');
$table->timestamps();
$table->foreign('category_id')
->references('id')
->on('category');
});
}
异常跟踪:
PDOException::("SQLSTATE[HY000]: 一般错误:3780 在外键约束 'peaces_category_id_foreign' 中引用列 'category_id' 和引用列 'id' 不兼容。")
【问题讨论】:
标签: laravel