LoginSignup
7
4

More than 3 years have passed since last update.

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definitionの解消

Posted at

タイトルのエラーについて

docker上でテーブルを作成しようとphp artisan migrateをかけたら初めてこのエラーに遭遇
解消法はいたって簡単
最初に書いていたmigrationファイル

migration.php
Schema::create('questions', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->increments('tag_category_id');
            $table->string('title');
            $table->text('content');
            $table->timestamps();
            $table->softDeletes();
        });

これだとタイトルのエラーが出た。
立てた仮説は主キーがふたつできてしまっているからエラーになっているのではないかと予想。
なので、こう変更して再びマイグレーション。

migration.php
Schema::create('questions', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id');
            $table->integer('tag_category_id'); //変更
            $table->string('title');
            $table->text('content');
            $table->timestamps();
            $table->softDeletes();
        });

結果

無事マイグレーションが成功

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4