Skip to content

Migrating a TEXT field to JSON incorrectly sets COLLATE and MySQL throws an error #25735

Closed
@poisa

Description

@poisa
  • Laravel Version: 5.6.29
  • PHP Version: 7.1.20
  • Database Driver & Version: MySQL 5.7.23
  • doctrine/dbal Version: 2.8.0

Description:

I expect the generated SQL to change a column to json to include a valid collation for a JSON field (such as binary) or no collation at all:

ALTER TABLE mytable CHANGE mycolumn mycolumn JSON DEFAULT NULL

The actual SQL generated is:

ALTER TABLE mytable CHANGE mycolumn mycolumn JSON DEFAULT NULL COLLATE utf8mb4_unicode_ci

This results in the following error:

SQLSTATE[42000]: Syntax error or access violation: 1253 COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'binary'

Steps To Reproduce:

While creating a table set a field to TEXT:

$table->text('mycolumn')->nullable();

Then create a migration that attempts to change the field type to JSON:

$table->json('mycolumn')->nullable()->change();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions