簡體   English   中英

列存在但遷移時它返回 SQLSTATE[42000]:語法錯誤或訪問沖突:1072 表中不存在鍵列

[英]column exist but when migration it returns SQLSTATE[42000]: Syntax error or access violation: 1072 Key column doesn't exist in table

列存在但遷移時返回

SQLSTATE[42000]:語法錯誤或訪問沖突:1072 表中不存在鍵列

當我刪除外鍵時,問題就解決了

  public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $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('skills', function (Blueprint $table) {
        $table->increments('id');
        $table->string('skill_name')->nullable();
        $table->decimal('skill_note')->nullable();           
        $table->timestamps();
    });
}


   public function up()
    {
        Schema::create('skill_user', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id');
            $table->foreign('user_id ')
                ->references('id')->on('users');
            $table->unsignedInteger('skill_id');
            $table->foreign('skill_id')
                ->references('id')->on('skills');
            $table->decimal('note')->nullable();
            $table->timestamps();
        });
    }

在第 6 版(您用於我在評論中讀到的內容的那個)中, increments('id') 方法不會創建無符號整數,而是創建一個無符號大整數,因此您需要更改您的外鍵

$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('skill_id');

試試這個。

 $table->integer('user_id')->unsigned(); $table->integer('skill_id')->unsigned();

如果它不起作用,我建議運行 composer install 和 migrate:fresh

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM