skip to Main Content

Error: 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 (SQL: create table subscriptions (id bigint unsigned not null auto_increment primary key, month int unsigned not null auto_increment primary key, price int unsigned not null auto_increment primary key, status tinyint not null default ‘1’, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate ‘utf8mb4_unicode_ci’)

I have applied this code given below:

    {
        Schema::create('subscriptions', function (Blueprint $table) {
            $table->id();
            $table->integer('month',4);
            $table->integer('price',7);
            $table->tinyInteger('status')->default(1);
            $table->timestamps();
        });
    } ```

2

Answers


  1. You can’t set a size on integers.

    It should be like this:

     $table->integer('month');
     $table->integer('price');
    
    
    Login or Signup to reply.
  2. first of all, you can’t set size on integers second instead of tinyInteger use boolean

        {
            Schema::create('subscriptions', function (Blueprint $table) {
                $table->id();
                $table->integer('month');
                $table->integer('price');
                $table->boolean('status')->default(1);
                $table->timestamps();
            });
        }
    

    and I would suggest using decimal for price because it may contain a decimal places

    table->decimal('price', 10, 6)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search