Home > Back-end >  Laravel 1075 Incorrect table definition; there can be only one auto column and it must be defined as
Laravel 1075 Incorrect table definition; there can be only one auto column and it must be defined as

Time:06-09

I Have getting the error while using the migration in laravel 9.0.1.

 public function up()
       {
           Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_goal_id')->constrained('user_goals')->onDelete('cascade');
            $table->string('full_name', 50)->nullable();
            $table->string('last_name', 50)->nullable();
            $table->enum('gender', ['Male', 'Female', 'Others'])->default('Male');
            $table->decimal('weight', 4, 2)->nullable();
            $table->bigInteger('height', 20)->nullable();
            $table->bigInteger('age', 10)->nullable();
            $table->enum('status', ['Active', 'Inactive'])->default('Active');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
       }

Error is: SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key.

How can i solve this?

CodePudding user response:

change your height & age column to

...
$table->integer('height')->nullable();
$table->integer('age')->nullable();

Reason:

$table->bigInteger('height', 20)->nullable();

$table->bigInteger('age', 10)->nullable();

//its SQL convert like below

`height` int null auto_increment primary key, 
`age` int null auto_increment primary key,"

// so you can't add primary key multiple time

  • Related