2

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')
5
  • 1
    Because you create $table->primary(['seq', 'create_dt', 'region_nm']); Commented Jul 9, 2021 at 6:10
  • You mean $table->integer('defCnt', 15)->default(0) would make this field autoincrement and primary? Commented Jul 9, 2021 at 6:17
  • Nope I want only default value 0 not AI and PK on type integer column Commented Jul 9, 2021 at 6:19
  • This should not be happening with integer though I'm not sure the 2nd parameter should be used there. Can you share the exact Laravel version you are using? Commented Jul 9, 2021 at 6:33
  • Directly tell about with sql text My plan was create table 'tbl_corona_region' ( 'seq' varchar(30) not null, 'create_dt' date not null, 'region_nm' varchar(30) not null, 'defCnt' int(15) not null default '0' ..... primary key ('seq', 'create_dt', 'region_nm') ) ... Commented Jul 9, 2021 at 6:40

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.