我一直在嘗試不同的方式,但我無法消除錯誤。所以我的問題是:其他人可以看到錯誤嗎?這是我的代碼: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_id
和created_by
被定義為bigIncrements
,所以您不能定義它們的外鍵,因為unsignedInteger
它需要是相應的數據類型,根據文檔是:
自動遞增 UNSIGNED BIGINT(主鍵)等效列。
這相當于unsignedBigInteger
。
改變,
$table->unsignedInteger('places_id'); $table->unsignedInteger('created_by');
到,
$table->unsignedBigInteger('places_id'); $table->unsignedBigInteger('created_by');
- 1 回答
- 0 關注
- 258 瀏覽
添加回答
舉報
0/150
提交
取消