0

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?

CXJ
  • 4,301
  • 3
  • 32
  • 62
  • This was addressed here: https://stackoverflow.com/questions/39904183/cakephp-migrations-how-to-specify-scale-and-precision – miken32 Apr 28 '21 at 19:49
  • FYI the `float(M, D)` syntax is deprecated and will be removed from a future version of MySQL, so you might think twice about designing your app with this in mind. Ref: https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html – Bill Karwin Apr 28 '21 at 19:50
  • @miken32: that only addresses decimal and numeric types, not float. Bill Karwin: Thanks for pointing that out! If I were designing my app, I'd follow that advice. But I'm modifying some really old legacy code, so don't have that choice. ;-) – CXJ Apr 30 '21 at 00:23

1 Answers1

0

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();
}
CXJ
  • 4,301
  • 3
  • 32
  • 62