Home > Net >  I'm trying migration and it is throwing Exception Error?
I'm trying migration and it is throwing Exception Error?

Time:10-21

Code:

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

Error: QLSTATE[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 not null auto_increment primary key, price int 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')

CodePudding user response:

Solution: I solved my error doing this because we can't set a size on integers.

 $table->integer('month');
 $table->integer('price');

CodePudding user response:

The second parameter in integer is a boolean.

If true the field is autoincrement

Remove 4 and 7 from integer.

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