6

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 ?.

Jishad
  • 2,876
  • 8
  • 33
  • 62

1 Answers1

3

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'
    );
}
Saumini Navaratnam
  • 8,439
  • 3
  • 42
  • 70