久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

laravel errno 150 外鍵約束的格式不正確

laravel errno 150 foreign key constraint is incorrectly formed(laravel errno 150 外鍵約束的格式不正確)
本文介紹了laravel errno 150 外鍵約束的格式不正確的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

誰能幫我解決這個問題?

Can anybody help me to solve this problem?

有 3 個表,有 2 個外鍵:

There are 3 tables with 2 foreign keys:

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('email')->unique();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

Schema::create('firms', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title')->nullable();
    $table->integer('user_id')->unsigned()->nullable();
    $table->foreign('user_id')->references('id')->on('users');
    $table->timestamps();
});

Schema::create('jobs', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title')->nullable();
    $table->integer('firm_id')->unsigned()->nullable();
    $table->foreign('firm_id')->references('id')->on('firms');
    $table->timestamps();
});
                    

運行遷移后出錯:

[IlluminateDatabaseQueryException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `job`.`#sql-5fc_a1`
   (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter ta
  ble `firms` add constraint `firms_user_id_foreign` foreign key (`user_id`)
  references `users` (`id`))

  [PDOException]
  SQLSTATE[HY000]: General error: 1005 Can't create table `job`.`#sql-5fc_a1`
   (errno: 150 "Foreign key constraint is incorrectly formed")

推薦答案

如果是外鍵,引用字段和引用字段的數據類型必須完全相同.

In case of foreign keys, the referenced and referencing fields must have exactly the same data type.

您將usersfirms 中的id 字段創建為有符號 整數.但是,您將兩個外鍵創建為無符號 整數,因此鍵的創建失敗.

You create the id fields in both users and firms as signed integers. However, you create both foreign keys as unsigned integers, therefore the creation of the keys fail.

您需要將 unsigned 子句添加到 id 字段定義中,或者從外鍵字段中刪除 unsigned 子句.

You need to either add the unsigned clause to the id field definitions, or remove the unsigned clause from the foreign key fields.

這篇關于laravel errno 150 外鍵約束的格式不正確的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 久久精品91久久久久久再现 | 日韩午夜影院 | 国产一区二区三区四区 | 欧美黄色绿像 | 羞羞网站在线免费观看 | 欧美精品在线观看 | 人人人艹 | 国产91在线 | 欧美 | 亚洲性视频网站 | 国产免费一区二区三区免费视频 | 成人一区二区在线 | 日韩精品在线观看免费 | 免费在线观看一区二区三区 | 国产精品一区二区av | 中文字幕av一区二区三区 | 国产成人精品视频在线观看 | 精精久久 | 久久国产精品-国产精品 | 仙人掌旅馆在线观看 | 久久中文免费视频 | 国产精品久久久av | 日韩欧美一区二区三区四区 | 影音先锋中文字幕在线观看 | 国产精品欧美一区二区三区 | 在线免费观看毛片 | 91免费高清视频 | 久久乐国产精品 | 国产一区二区在线视频 | 久久久婷婷 | 国产精品国产a | 亚洲国产视频一区二区 | 精品视频免费 | 国产一区二区久久 | 亚洲人人舔人人 | 日韩欧美在线观看视频 | 91精品久久久久久久久久小网站 | 国产一区在线免费观看 | 国产精品美女久久久久久久网站 | 国产精品毛片在线 | 亚洲 中文 欧美 日韩 在线观看 | 91成人在线 |