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’)
3
Answers
Solution: I solved my error doing this because we can't set a size on integers.
The second parameter in integer is a boolean.
If true the field is autoincrement
Remove 4 and 7 from integer.
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: