NOT NULL constraint failed after Laravel 11 upgrade #52182
Replies: 3 comments 2 replies
-
Hi. From experience, change() usually replaces the column definition except that when the type is the same, then only the specified attributes change on mysql from what I saw. Ex length for strings and the default remains the same if not specified. In mysql your change would transform the tiny int into int so I guess that is a type change. |
Beta Was this translation helpful? Give feedback.
-
See this. #52180 (comment) It seems it is expected nehavior acc. to documentation. |
Beta Was this translation helpful? Give feedback.
-
This is expected behavior since 10.x. You may check PR #45487 that explains the reason behind this. Also explained on 11.x upgrade guide. |
Beta Was this translation helpful? Give feedback.
-
I have a bunch of these errors happening since upgrading to Laravel 11 and figured out it is due to some migrations where the column type has changed.
Original:
$table->boolean('enable')->default(1);
Updated:
$table->integer('enable')->change();
It seems to lose the default value when changing the type. This has never been an issue as far as I am aware in previous versions.
It is fixed by doing this:
$table->integer('enable')->change()->default(1);
Does anyone know if this is a bug or expected behaviour? I can see both points.
Beta Was this translation helpful? Give feedback.
All reactions