I am new to laravel.
Now i am using the migrate command to make a table, but the length of the filed is not applicable. Laravel does not provide this option. ?
Below is my codes:
$table->increments('id')->length(11);
$table->dateTime('created_time');
$table->integer('bank_id')->length(11);
$table->tinyInteger('is_black')->length(1);
The length of the field is_black
should be 1, but it is actually being generated as 4.
How can I solve this problem ?
Any suggestion or advice would be appreciated.
Thank you in advance
In our case we are going to do second option - create new migration. If we roll back this migration, we need to remove default value from that field using migration and this is how to do it: Schema::table('photos', function (Blueprint $table) { $table->integer('order')->default(NULL)->change(); });
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
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');
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');
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."'");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With