You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Renaming a column in a table that has composite foreign keys fails with the following message:
Knex:warning - migration file "20181115140157_plugin-core-publish-schedule.js" failed
Knex:warning - migration failed with error: alter table `page` drop foreign key `page_id_content_type_id_foreign` - ER_CANT_DROP_FIELD_OR_KEY: Can't DROP 'page_id_content_type_id_foreign'; check thatcolumn/key exists
Warning: alter table `page` drop foreign key `page_id_content_type_id_foreign` - ER_CANT_DROP_FIELD_OR_KEY: Can't DROP 'page_id_content_type_id_foreign'; check that column/key exists Use --force to continue.
Here are the simplified definitions of the tables causing this:
renameColumn drops all foreign keys on a table, it should only drop foreign keys that reference the column being renamed
when renameColumn drops foreign keys, it attempts to drop composite foreign keys multiple times (once for each column in the key)
In my case since there are no foreign keys that reference the column I'm renaming, I can just do:
constrenameColumn=async(knex,table,columnOld,columnNew)=>{const[[columnCurrent]]=awaitknex.raw(`show fields from content where field = '${columnOld}'`);letsql=`alter table \`${table}\` change \`${columnOld}\` \`${columnNew}\` ${columnCurrent.Type}`;if(String(columnCurrent.Null).toUpperCase()!=='YES'){sql+=' NOT NULL';}if(columnCurrent.Default!==undefined&&columnCurrent.Default!==null){sql+=` DEFAULT '${columnCurrent.Default}'`;}awaitknex.raw(sql);};exports.up=async(knex)=>{awaitrenameColumn(knex,'content','published_at','publish_from');};exports.down=async(knex)=>{awaitrenameColumn(knex,'content','publish_from','published_at');};
The text was updated successfully, but these errors were encountered:
Environment
Knex version: 0.14.6
Database + version: MySQL 5.7.21
OS: macOS 10.13.6
Bug
Renaming a column in a table that has composite foreign keys fails with the following message:
Here are the simplified definitions of the tables causing this:
Setup these table, then create and run a migration containing:
The problem here seems to be twofold:
renameColumn
drops all foreign keys on a table, it should only drop foreign keys that reference the column being renamedrenameColumn
drops foreign keys, it attempts to drop composite foreign keys multiple times (once for each column in the key)In my case since there are no foreign keys that reference the column I'm renaming, I can just do:
The text was updated successfully, but these errors were encountered: