How to set scale and precision for MySQL float column in Phinx migration

388 Views Asked by At

I've got a column in a current MySQL table with definition float(3,2) and I need to expand it to be float(4,2). How do I do this with a Phinx (CakePHP) migration column specification?

1

There are 1 best solutions below

0
On

The following appears to work, but is undocumented in both the Phinx and CakePHP documentation. Use at your own risk, and test that the correct results are being generated. The keys are scale for digits to right of decimal point and precision for maximum digits (width).

public function up(): void
{
    $this->table('my_table')
        ->changeColumn('my_column', 'float', ['scale' => 2, 'precision' => 4])
        ->save();
}