Can't drop a column in a migration

Open
#1,256 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, mariadb, mysql
Domain
databases

Research direction

Start by reproducing the migration's queryInterface.removeColumn call against MariaDB 10.7, using the SQL and error shown in the issue. Trace the removeColumn implementation and its constraint lookup, then verify that the migration completes and the id_Sage column is dropped without the reported error.

Written by the indexing model from the issue text.

Description

What you are doing?

'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
    async up(queryInterface, Sequelize) {
        await queryInterface.removeColumn('user', 'id_Sage', {
            logging: (sql) => console.error(sql),
        });
    },

    async down(queryInterface, Sequelize) {
        return false;
    },
};

What do you expect to happen?

I expected the column to be dropped

What is actually happening?

An error occurs which prevents me from migrating my DB

▶ yarn run db:migrate
yarn run v1.22.19
$ sequelize db:migrate

Sequelize CLI [Node: 18.14.0, CLI: 6.6.0, ORM: 6.6.5]

Loaded configuration file "libs/db/src/config/database/index.js".
Using environment "development".
== 20230224101241-remove-idSage-from-user: migrating =======
Executing (default): SELECT CONSTRAINT_NAME as constraint_name,CONSTRAINT_NAME as constraintName,CONSTRAINT_SCHEMA as constraintSchema,CONSTRAINT_SCHEMA as constraintCatalog,TABLE_NAME as tableName,TABLE_SCHEMA as tableSchema,TABLE_SCHEMA as tableCatalog,COLUMN_NAME as columnName,REFERENCED_TABLE_SCHEMA as referencedTableSchema,REFERENCED_TABLE_SCHEMA as referencedTableCatalog,REFERENCED_TABLE_NAME as referencedTableName,REFERENCED_COLUMN_NAME as referencedColumnName FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE (REFERENCED_TABLE_NAME = 'user' AND REFERENCED_TABLE_SCHEMA = 'database' AND REFERENCED_COLUMN_NAME = 'id_Sage') OR (TABLE_NAME = 'user' AND TABLE_SCHEMA = 'database' AND COLUMN_NAME = 'id_Sage' AND REFERENCED_TABLE_NAME IS NOT NULL)

ERROR: Cannot delete property 'meta' of [object Array]

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Dialect: mysql/mariadb
Database version: 10.7
Sequelize CLI version: 6.6.0
Sequelize version: 6.6.5

Dominant language
JavaScript
Stars
2.6k
Forks
524
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sequelize/cli

All issues in sequelize/cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.