migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Problem with BLOB type when baking a migration

Open hacheraw opened this issue 5 years ago • 0 comments

This is a (multiple allowed):

  • [x] bug

  • [x] enhancement

  • [ ] feature-discussion (RFC)

  • CakePHP Version: 4.2.2

  • Platform and Target: Windows 10 (XAMPP) PHP 7.2, 10.1.35-MariaDB

What you did

I have some BLOB and MEDIUMBLOB columns on Database:

-- EXAMPLE
CREATE TABLE `measures` (
  `id` int(11) NOT NULL,
  `title` blob NOT NULL,
  `text` mediumblob NOT NULL,
  `created` datetime NOT NULL,
  `modified` datetime NOT NULL,
  `deleted` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

What happened

This is the resulting code after running bin/cake bake migration_diff measures:

$this->table('measures')
    ->addColumn('title', 'binary', [
        'default' => null,
        'limit' => null, // <----- PROBLEM HERE
        'null' => false,
    ])
    ->addColumn('text', 'binary', [
        'default' => null,
        'limit' => 16777215,
        'null' => false,
    ])

The problem is that when you run that migration in another machine using bin/cake migrations migrate

the resulting column type for title is not BLOB but BINARY(255) image

What you expected to happen

If ColumnType is BLOB, the limit should be 65535. (Stack Overflow)

What you have tried

I edited the migration, replaced the 'limit' => null with 'limit' => 65535 and ran the migration in a blank database. It worked as espected. image

hacheraw avatar Jan 10 '21 23:01 hacheraw