Reputation: 59
When I try database migrations Scheme Builder from Laravel.
When I enter a type integer, auto_increment and primary key are automatically inputed.
I don't know how to get a create table in laravel.
Schema::create('tbl_corona_region', function(Blueprint $table){
$table->string('seq', 30);
$table->date('create_dt');
$table->string('region_nm', 30);
$table->string('region_cn', 30);
$table->string('region_en', 30);
$table->integer('defCnt', 15)->default(0);
$table->integer('incDec', 15)->default(0);
$table->integer('deathCnt', 15)->default(0);
$table->integer('isolIngCnt', 15)->default(0);
$table->integer('isolClearCnt', 15)->default(0);
$table->integer('localOccCnt', 15)->default(0);
$table->integer('overFlowCnt', 15)->default(0);
$table->integer('qurRate', 15)->default(0);
$table->dateTime('stdDay');
$table->dateTime('update_dt');
$table->primary(['seq', 'create_dt', 'region_nm']);
});
Generates this SQL
create table `tbl_corona_region` (
`seq` varchar(30) not null,
`create_dt` date not null,
`region_nm` varchar(30) not null,
`region_cn` varchar(30) not null,
`region_en` varchar(30) not null,
`defCnt` int not null default '0' auto_increment primary key,
`incDec` int not null default '0' auto_increment primary key,
`deathCnt` int not null default '0' auto_increment primary key,
`isolIngCnt` int not null default '0' auto_increment primary key,
`isolClearCnt` int not null default '0' auto_increment primary key,
`localOccCnt` int not null default '0' auto_increment primary key,
`overFlowCnt` int not null default '0' auto_increment primary key,
`qurRate` int not null default '0' auto_increment primary key,
`stdDay` datetime not null,
`update_dt` datetime not null
) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
Upvotes: 2
Views: 9679
Reputation: 4808
The second parameter in integer is autoincrement
not length.
In the laravel database migration, the integer type cannot be specified in length. It takes 11 as default.
The second parameter of the integer method is not the specified length. Instead, the auto increment is set, so the integer method cannot specify the length of the sub-segment.
integer(string $column, bool $autoIncrement = false, bool $unsigned =false)
Reference : Laravel core implementation of integer method
Upvotes: 3