Jishad
Jishad

Reputation: 2965

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

Upvotes: 6

Views: 2099

Answers (1)

Saumini Navaratnam
Saumini Navaratnam

Reputation: 8850

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'
    );
}

Upvotes: 3

Related Questions