-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Migrations] Rename column changes default from NULL to 'NULL' #22050
Comments
A possible workaround would be to reset the default column value before and after each migration operation. public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->string('name')->default(null)->change();
});
Schema::table('products', function (Blueprint $table) {
$table->renameColumn('name', 'description');
});
Schema::table('products', function (Blueprint $table) {
$table->string('description')->default(null)->change();
});
}
public function down()
{
Schema::table('products', function (Blueprint $table) {
$table->string('description')->default(null)->change();
});
Schema::table('products', function (Blueprint $table) {
$table->renameColumn('description', 'name');
});
Schema::table('products', function (Blueprint $table) {
$table->string('name')->default(null)->change();
});
} This makes it possible to roll this migration back and forth with no errors. |
It's a known issue with MariaDB 10.2.7 that broke stuff. See #21140 and doctrine/dbal#2825 Note that MariaDB is missing in the list of supported databases.
Source: #11518 (comment) |
Concerning the mariadb support, see Taylor's follow up comment. #11518 (comment) |
The linked comment does not at all mentioned MariaDB, only MySQL 5.7. The context is changes in MySQL over time, not MariaDB support. |
Ah true. I've misinterpreted that comment for the past 2 years. I guess this tweet threw me off concerning Maria support, and I was simply responding to the idea that Laravel doesn't officially support Maria. |
Installing the latest Homestead causes this problem to manifest itself if you specify |
This has been fixed in |
mysql Ver 15.1 Distrib 10.2.10-MariaDB
Description:
When renaming a nullable string column the default value changes from the database
NULL
to a literal string'NULL'
.This itself isn't the whole issue. When trying to rollback the last migration:
the following exception is thrown:
Steps To Reproduce:
up
method of the created migration class add:Product::create();
The output from the last command should show, that the default value for the column in question has been changed from the database
NULL
to a string'NULL'
.The first product was created in the third of these steps and its
description
property has the correctnull
value. The second one was created in the last step and has the new, incorrect'NULL'
value for thedescription
property.The text was updated successfully, but these errors were encountered: