Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Undocumented additional behaviour when calling renameColumn() #5998

@wodlo

Description

@wodlo

It looks like the documentation on this function call is very sparse. https://knexjs.org/guide/schema-builder.html#renamecolumn

It just says Renames a column from one name to another. which is what I expected it to do.

When calling this function using the mysql2 driver I was expecting it to a run a very simple ALTER TABLE x RENAME COLUMN y TO z statement.

What actually happened is it dropped every foreign key pointing to the table I was renaming a column on, and then re-added the keys afterwards.

This ended up dropping a foreign key on an enormous table which took around 7 hours to re-add.

Looking at the code in lib/dialects/mysql/schema/mysql-tablecompiler.js this does appear to be the expected behaviour. I can see it calls getFKRefs() followed by a dropFKRefs() and then a final createFKRefs() once the columns have been renamed.

It would be nice if this additional behaviour was documented so users are aware that they should use knex.raw() on mysql when simply re-naming a column rather than using the renameColumn() function

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions