Skip to content

Commit bdeae41

Browse files
committed
fix renaming column in migration
see: laravel/framework#34884
1 parent b2a5cd8 commit bdeae41

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Illuminate/Database/Schema/Grammars/Grammar.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,22 @@ protected function getRenamedDiff(Blueprint $blueprint, Fluent $command, Column
6363
*/
6464
protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column)
6565
{
66-
$newColumn = new Column($command->to, $column->getType(), $column->toArray());
67-
68-
$tableDiff->renamedColumns = array($command->from => $newColumn);
66+
$tableDiff->renamedColumns = array(
67+
$command->from => new Column($command->to, $column->getType(), self::getWritableColumnOptions($column))
68+
);
6969

7070
return $tableDiff;
7171
}
7272

73+
private static function getWritableColumnOptions(Column $column): array
74+
{
75+
return array_filter(
76+
$column->toArray(),
77+
fn (string $name) => method_exists($column, 'set'.$name),
78+
ARRAY_FILTER_USE_KEY
79+
);
80+
}
81+
7382
/**
7483
* Compile a foreign key command.
7584
*

0 commit comments

Comments
 (0)