You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In upgrading to Laravel 11, I've discovered an interesting artifact regarding the section on Modifying Columns. The order of calling change() and nullable() seem to matter and $table->string('column_a')->nullable()->change() seems not equivalent to $table->string('column_a')->change()->nullable().
The first migration simply adds a column of type string to the table, the following migration changes this datatype from string to longtext. From the earlier mentioned upgrade guide, it is expected that the nullable property is dropped.
Now, the interesting part: when updating the second migration to include the nullable() property as mentioned in the documented example, the column remains the type of NOT NULL in the database upon inspection.
What I did find is that changing the order of calling nullable() and change() does work! So using the following migration does actually work to obtain the correct datatype column which is nullable:
If this is actually expected/desired behavior, just the example on the documentation page might need an update.
Steps To Reproduce
Reproducing the error
Using the provided Laravel version, create two simple migrations that 1) add a new nullable column to an existing table; 2) update the type of the column and try to make it nullable by using the example as mentioned on the Laravel 11 upgrade page:
I have just double checked by swapping the calls in my local test setup and now they do appear to both yield the same result. I'm really sorry for the confusion. This must have been a me-problem.
I'm really sorry for the confusion and want to thank you for your time @hafezdivandari
Laravel Version
11.0.8
PHP Version
8.2.13
Database Driver & Version
MySQL 8.0
Description
In upgrading to Laravel 11, I've discovered an interesting artifact regarding the section on Modifying Columns. The order of calling
change()
andnullable()
seem to matter and$table->string('column_a')->nullable()->change()
seems not equivalent to$table->string('column_a')->change()->nullable()
.In my project I have these two migrations:
The first migration simply adds a column of type
string
to the table, the following migration changes this datatype fromstring
tolongtext
. From the earlier mentioned upgrade guide, it is expected that thenullable
property is dropped.Now, the interesting part: when updating the second migration to include the
nullable()
property as mentioned in the documented example, the column remains the type of NOT NULL in the database upon inspection.What I did find is that changing the order of calling
nullable()
andchange()
does work! So using the following migration does actually work to obtain the correct datatype column which is nullable:Disclaimer
If this is actually expected/desired behavior, just the example on the documentation page might need an update.
Steps To Reproduce
Reproducing the error
Using the provided Laravel version, create two simple migrations that 1) add a new nullable column to an existing table; 2) update the type of the column and try to make it nullable by using the example as mentioned on the Laravel 11 upgrade page:
When running the migrations, notice that the column does not have a nullable type.
Reproducing the happy path
Now, switch
->nullable()->change();
to->change()->nullable();
.The column now is actually nullable.
The text was updated successfully, but these errors were encountered: