Laravel 5.5 set size of integer fields in migration file

ID : 274472

viewed : 43

Tags : laravellaravel-5.5laravel





Top 5 Answer for Laravel 5.5 set size of integer fields in migration file

vote vote

92

You can't do this, but you can use different types of integer:

$table->bigInteger() $table->mediumInteger() $table->integer() $table->smallInteger() $table->tinyInteger() 

https://laravel.com/docs/5.5/migrations#columns

vote vote

83

According to https://laravel.com/docs/5.1/migrations, as of Laravel 5.1 you can use the boolean column type to create a "boolean-like" TINYINT of length 1 (MySQL). So, for example:

$table->boolean('nameOfColumn'); 
vote vote

70

According to https://laravel.com/docs/5.5/migrations, you can use one of these types:

$table->bigInteger('votes'); $table->integer('votes');  $table->mediumInteger('votes');  $table->smallInteger('votes'); $table->tinyInteger('votes'); $table->unsignedBigInteger('votes'); $table->unsignedMediumInteger('votes');  $table->unsignedSmallInteger('votes');   $table->unsignedTinyInteger('votes');    
vote vote

67

this is solution for me! Inside on function run.

    $tableName = 'tblresefeage';     $comments = 'Resumen efectividad por agencia';     Schema::create($tableName, function (Blueprint $table) {         $table->bigIncrements('id');         $table->unsignedInteger('agencia')->comment('Agencia');         $table->date('fechacierre')->comment('Fecha cierre');                    $table->timestamps();     });     DB::statement('ALTER TABLE tblresefeage MODIFY COLUMN agencia INTEGER (11);');      Schema::table($tableName, function (Blueprint $table) {         $table->foreign('agencia')->on('tblentage')->references('cveentage')->onDelete('cascade');     });      DB::statement("ALTER TABLE `$tableName` comment '".$comments."'"); 
vote vote

54

This code works for me.

$table->addColumn(     'tinyInteger', 'field_name',     [         'length'   => 2,         'default'  => '1',         'autoIncrement' => false,         'unsigned' => true,         'comment'  => 'Some comments'     ] ); 

Top 3 video Explaining Laravel 5.5 set size of integer fields in migration file







Related QUESTION?