@@ -607,6 +607,24 @@ protected function afterClause(Column $column): string
607607 */
608608 protected function getRenameColumnInstructions (string $ tableName , string $ columnName , string $ newColumnName ): AlterInstructions
609609 {
610+ $ columns = $ this ->getColumns ($ tableName );
611+ $ targetColumn = null ;
612+
613+ foreach ($ columns as $ column ) {
614+ if (strcasecmp ($ column ->getName (), $ columnName ) === 0 ) {
615+ $ targetColumn = $ column ;
616+ break ;
617+ }
618+ }
619+
620+ if ($ targetColumn === null ) {
621+ throw new InvalidArgumentException (sprintf (
622+ "The specified column doesn't exist: %s " ,
623+ $ columnName ,
624+ ));
625+ }
626+
627+ // Fetch raw MySQL column info for the full definition string
610628 $ rows = $ this ->fetchAll (sprintf ('SHOW FULL COLUMNS FROM %s ' , $ this ->quoteTableName ($ tableName )));
611629
612630 foreach ($ rows as $ row ) {
@@ -624,8 +642,10 @@ static function ($value) {
624642 $ extra = ' ' . implode (' ' , $ extras );
625643
626644 if (($ row ['Default ' ] !== null )) {
627- $ phinxTypeInfo = $ this ->getPhinxType ($ row ['Type ' ]);
628- $ extra .= $ this ->getDefaultValueDefinition ($ row ['Default ' ], $ phinxTypeInfo ['name ' ]);
645+ $ columnType = $ targetColumn ->getType ();
646+ // Column::getType() can return string|Literal, but getDefaultValueDefinition expects string|null
647+ $ columnTypeName = is_string ($ columnType ) ? $ columnType : null ;
648+ $ extra .= $ this ->getDefaultValueDefinition ($ row ['Default ' ], $ columnTypeName );
629649 }
630650 $ definition = $ row ['Type ' ] . ' ' . $ null . $ extra . $ comment ;
631651
0 commit comments