Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Changing Migration field Float to Double

I want to create a table with a float column.

$table->float('TaxRate',5,5)->default(0.00000);

But Mysql Taking this as a DOUBLE.

enter image description here

How this working ?.

like image 597
Jishad Avatar asked Nov 19 '16 05:11

Jishad


1 Answers

It because Illuminate\Database\Schema\Grammars\MySqlGrammar converts float into double. I don't know the reason why they enforce it to use double.

Overriding the MySqlGrammar will be troublesome, since you will have to override more classes.

You can use raw mysql query to create table like below

public function up() {
    DB::unprepared('CREATE TABLE `temp`(
        `id` INT NOT NULL AUTO_INCREMENT,
        `tax_rate` FLOAT(5, 5) NOT NULL DEFAULT 0.00000,
        ...
        PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8'
    );
}
like image 119
Saumini Navaratnam Avatar answered Oct 09 '22 16:10

Saumini Navaratnam