Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[6.x] Wrap MySQL default values in parentheses #29878
Prior to MySQL 8.0.13, types of
This made JSON fields cast as Collections annoying to handle when the value was
As of MySQL 8.0.13, we can now add default values to these fields, but a minor change needs to be made in the grammar. These fields can be assigned a default value only if the value is written as an expression, even if the expression value is a literal.
This will not work:
CREATE TABLE t2 (b BLOB DEFAULT 'abc');
but this will:
CREATE TABLE t2 (b BLOB DEFAULT ('abc'));
Originally I was going to conditionally check for the field type and only apply the parentheses for the required types, but that seemed like overkill. Only if there were performance or other implications for making every default value an expression would I think we would need to do that.
I won't presume to know how the other DB engines handle this, but there's a decent chance these changes will need to be made to them as well.
On a side note, now that we've switched to SemVer, do we need to indicate in our PRs if we think they are minor or patch commits?
No, I think the plan is just, on release day, it will be decided if patch or minor version is bumped. Usually, minor version I guess.
Right, so as I thought. :P
Sep 6, 2019
Heads up that this broke one of my migrations after updating from 6.0.1 to 6.0.2.
I had an old migration class with:
This broke because of the PR. I received the error:
@taylorotwell I'm thinking we should revert this for now, because it appears MySQL prior to 8.0.13 cannot handle "expressions" as their default value.
What I am going to propose is a new method on the schema grammar called
Also experiencing this issue with defaults on integers. Just changed the MySqlGrammer back to ' return ' default '.$this->getDefaultValue($column->default);' as a temp fix.
Laravel is usually very anti
After digging into the source, I found out it's actually currently possible to add expressions as a default value.
I've sent a PR into the Docs to help explain how to use it: