我回來了:
SQLSTATE [HY000]:一般錯誤:3780 在外鍵約束“prodotti_categoria_id_foreign”中參考列“Categoria_id”和參考列“id”不兼容。(SQL:alter table
prodotti添加約束prodotti_categoria_id_foreign外鍵(Categoria_id)參考categorie(id))
但在我的遷移資料中是:
// Categorie
public function up()
{
//
Schema::create('categorie', function (Blueprint $table) {
$table->unsignedBigInteger('id')->autoIncrement();
$table->string('Nome');
$table->enum('Status',['Active','Disabled']);
});
}
// Prodotti:
public function up()
{
//
Schema::create('prodotti', function (Blueprint $table) {
$table->id();
$table->string('Marca');
$table->string('Nome');
$table->string('Descrizione');
$table->bigInteger('EAN');
$table->bigInteger('MINSAN');
$table->timestamps();
$table->unsignedInteger('Categoria_id');
$table->foreign('Categoria_id')->references('id')->on('categorie');
});
}
uj5u.com熱心網友回復:
更改型別categoria_id如下;
$table->unsignedBigInteger('Categoria_id');
所以它匹配外鍵。
uj5u.com熱心網友回復:
在categoria中,您有以下內容:
$table->unsignedBigInteger('id')->autoIncrement();
在prodotti你有這個:
$table->unsignedInteger('Categoria_id');
注意型別是如何不同的,一個是unsignedBigInteger,另一個是unsignedInteger。您必須使用相同的型別。
編輯:
為什么這是一個問題?
因為unsignedBigInteger可以增長超過unsignedInteger因此您將處于不再支持映射的地步,因為一個將繼續增長,但另一個將達到其限制。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/421484.html
標籤:
