Skip to content

Change column in SQLite loses indices #2033

Closed

Description

@joerx

Seems when using a 'changeColumn' query with SQLite in a migration causes any indices on that table to be lost. That's caused by the fact that the affected table will be dropped and re-created. When recreating the table, the associated indices are 'forgotten'.

The MySQL dialect does not have this issue.

Activity

  1. jamiemccrindle commented on Jul 22, 2014

    @jamiemccrindle

    This is also true of the primary key of the table

    id INTEGER PRIMARY KEY

    becomes

    id INTEGER DEFAULT NULL

    The code the resulted in this change on our side doesn't touch the id

      return migration.changeColumn('some_table', 'some_column', {
        type: DataTypes.BIGINT(20),
        allowNull: true
      });
    

    output from the sequelize migration:

    Executing (undefined): CREATE TEMPORARY TABLE IF NOT EXISTS `some_table_backup` (`id` INTEGER DEFAULT NULL, `some_column` BIGINT(20), `level` varchar(255) DEFAULT 'NULL', `product_id` int(11) DEFAULT 'NULL', `name` VARCHAR(191) DEFAULT NULL, `free` TINYINT(1) DEFAULT NULL, `active` TINYINT(1) DEFAULT NULL);
    Executing (undefined): INSERT INTO some_table_backup SELECT id, some_column, level, product_id, name, free, active FROM some_table;
    Executing (undefined): DROP TABLE some_table;
    Executing (undefined): CREATE TABLE IF NOT EXISTS `some_table` (`id` INTEGER DEFAULT NULL, `some_column` BIGINT(20), `level` varchar(255) DEFAULT 'NULL', `product_id` int(11) DEFAULT 'NULL', `name` VARCHAR(191) DEFAULT NULL, `free` TINYINT(1) DEFAULT NULL, `active` TINYINT(1) DEFAULT NULL);
    Executing (undefined): INSERT INTO some_table SELECT id, some_column, level, product_id, name, free, active FROM some_table_backup;
    Executing (undefined): DROP TABLE some_table_backup;
    
  2. sushantdhiman commented on Jan 10, 2017

    @sushantdhiman
    Contributor

    Move to #7078

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

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions