Skip to content

[Bug]: Altering a column never backs up its foreign keys on MySQL and SQL Server #306

Open

Description

@roxblnfk

Describe the bug

Altering a column that a foreign key uses never drops and restores that foreign key on MySQL and SQL Server. MySQLHandler::alterColumn() (line 87) and SQLServerHandler::alterColumn() (line 181) select the keys to back up with $column->getName() === $foreign->getColumns(), comparing a string with an array, so the condition is always false: no key is dropped before the ALTER and none is restored after it.

Is this a regression?

Not checked; it dates from when getColumns() started returning an array.

To Reproduce

  1. MySQL or SQL Server; table post with user_id and a foreign key on it to user.id.
  2. Change the type or size of post.user_id through the schema and save().
  3. The ALTER runs with the foreign key still in place (the database rejects it, or the key is left as is), instead of the key being dropped and recreated around it.

Expected behaviour

in_array($column->getName(), $foreign->getColumns(), true): keys using the column are backed up, dropped and restored.

Media prove

Not applicable.

Database

MySQL, SQL Server.

Your environment

cycle/database 2.x, src/Driver/MySQL/MySQLHandler.php:87, src/Driver/SQLServer/SQLServerHandler.php:181.

Additional context

Found while raising coverage in #304: the backup branches are unreachable, so they stay uncovered.

Activity

  1. added
    status:to be verified
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:to be verifiedtype:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions