Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading