亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法添加或更新子行:外鍵約束失敗 - Laravel 7

無法添加或更新子行:外鍵約束失敗 - Laravel 7

PHP
BIG陽 2022-12-23 16:01:50
我正在嘗試1:1在我的訪客和聯系人之間添加關系<?phpuse Illuminate\Database\Migrations\Migration;use Illuminate\Database\Schema\Blueprint;use Illuminate\Support\Facades\Schema;class AddRelationToVisitorsDRelationToVisitorsContacts extends Migration{    public function up()    {        Schema::table('contacts', function(Blueprint $table)        {            $table->bigInteger('visitor_id')->unsigned();            $table->foreign('visitor_id')->references('id')->on('visitors')->onDelete('cascade');        });    }    public function down()    {        Schema::table('contacts', function($table)        {            $table->dropForeign('contacts_visitor_id_foreign');            $table->dropColumn('visitor_id');        });        Schema::table('visitors', function(Blueprint $table)        {            $table->dropColumn('contact_id');        });    }}運行時php artisan migrateMigrating: 2020_04_16_104641_update_contacts_table_04_16_2020
查看完整描述

3 回答

?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

在最新版本的 laravel 中,主鍵是 biginteger。所以你可能需要改變這個

$table->integer('visitor_id')->unsigned();

有了這個

$table->bigInteger('visitor_id')->unsigned();


查看完整回答
反對 回復 2022-12-23
?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

visitors 表中的 id 字段應該是bigIncrement類型



查看完整回答
反對 回復 2022-12-23
?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

如果您的表有數據,最好將已存在數據的列值設置為空,或將該列設置為可為空。

$table->bigInteger('visitor_id')->unsigned()->nullable();


查看完整回答
反對 回復 2022-12-23
  • 3 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號