0

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')

Psyco
  • 23
  • 6
  • 1
    Does this answer your question? [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](https://stackoverflow.com/questions/42053392/sqlstate42000-syntax-error-or-access-violation-1075-incorrect-table-definiti) – Mohd Dhiyaulhaq Oct 21 '22 at 07:20

3 Answers3

2

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

 $table->integer('month');
 $table->integer('price');
Psyco
  • 23
  • 6
0

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();
        });
    }
0

As Francesco Gallo said the Second parameter in an integer is a boolean. and if you are working with a price I highly recommend using a decimal instead of an integer.

so it would be better to write it like below:


public function up()
    {
        Schema::create('subscriptions', function (Blueprint $table) {
            $table->id();
            $table->integer('month');
            $table->decimal('price',5,3);
            $table->tinyInteger('status')->default(1);
            $table->timestamps();
        });
    }
Mohammad Edris Raufi
  • 1,393
  • 1
  • 13
  • 34