Skip to content
Advertisement

Change String to Decimal Laravel Migration

I’m trying to Alter my current table and can do it just fine with a SQL Query in my migration file like this:

But if I do it the this way I get an error:

ERROR:

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘CHARACTER SET utf8mb4 DEFAULT ‘0’ NOT NULL COLLATE utf8mb4_unicode_ci, CHANGE ‘ at line 1 (SQL: ALTER TABLE xyz CHANGE funding_needed funding_needed NUMERIC(10, 2) CHARACTER SET utf8mb4 DEFAULT ‘0’ NOT NULL COLLATE utf8mb4_unicode_ci, CHANGE funding_received funding_received NUMERIC(10, 2) CHARACTER SET utf8mb4 DEFAULT ‘0’ NOT NULL COLLATE utf8mb4_unicode_ci)

I want to do it the 2nd way due to running this in production. I don’t want to modify the production migration to match my production database.

Advertisement

Answer

As pointed on this Github thread for doctrine/dbal package, which is the package you install before you run this update migrations, there’s a bug on changing column types.

Using ->charset(null) along with ->change() should serve as a workaround in the meantime, as pointed on the link.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement