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

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

errno: 150“外鍵約束格式不正確”我該如何解決這個問題?

errno: 150“外鍵約束格式不正確”我該如何解決這個問題?

PHP
海綿寶寶撒 2022-01-08 17:28:11
我一直在嘗試不同的方式,但我無法消除錯誤。所以我的問題是:其他人可以看到錯誤嗎?這是我的代碼:public function up(){    Schema::create('users', function (Blueprint $table) {        $table->bigIncrements('id')->unique();        $table->boolean('admin')->default('0');        $table->string('name');        $table->string('email')->unique();        $table->timestamp('email_verified_at')->nullable();        $table->string('password');        $table->rememberToken();        $table->timestamps();    });}public function up(){    Schema::create('places', function (Blueprint $table) {        $table->bigIncrements('id')->unique();        $table->string('location_name');        $table->string('village');        $table->string('street');        $table->integer('number')->unsigned();    });}public function up(){    Schema::create('planning', function (Blueprint $table) {        $table->bigIncrements('id')->unique();        $table->unsignedInteger('places_id');        $table->time('van');        $table->time('tot');        $table->date('dag');        $table->timestamps();        $table->unsignedInteger('created_by');        $table->foreign('places_id')            ->references('id')            ->on('places')            ->onDelete('cascade');        $table->foreign('created_by')            ->references('id')            ->on('users')            ->onDelete('cascade');    });}PDOException::("SQLSTATE[HY000]: 一般錯誤: 1005 無法創建表`foodtruck`。`#sql-3be8_b8` (errno: 150 "外鍵約束格式不正確")")我希望這條錯誤消息離開我的命令行和我的遷移文件以我可以正常使用的方式修復:)
查看完整描述

1 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

因為places_idcreated_by被定義為bigIncrements,所以您不能定義它們的外鍵,因為unsignedInteger它需要是相應的數據類型,根據文檔是:

自動遞增 UNSIGNED BIGINT(主鍵)等效列。

這相當于unsignedBigInteger。

改變,

$table->unsignedInteger('places_id');
$table->unsignedInteger('created_by');

到,

$table->unsignedBigInteger('places_id');
$table->unsignedBigInteger('created_by');


查看完整回答
反對 回復 2022-01-08
  • 1 回答
  • 0 關注
  • 258 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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