Skip to content

SQLite migrations lose foreign keys on any column change #5007

Closed

Description

@jocull

I have a migration that iteratively walks through a series of columns, renaming them. However, I found that if I run a series of remove/create column calls, only the last one in keeps its foreign key constraint.

I believe it has to do with Sequelize's way of moving data into a backup table, performing changes, and then moving it back.

I'm not sure if this is a problem in other dialects.

Activity

  1. mickhansen commented on Dec 9, 2015

    @mickhansen
    Contributor

    Likely not a problem with other dialects since they have actual schema change capabilities.
    SQLite does not allow schema changes, the only way to do it is to backup, new table, transfer data.
    Looks like there's a bug with the new table creation.

  2. jocull commented on Dec 9, 2015

    @jocull
    Author

    I was able to work around it by calling describeTable, manipulating the
    description to be what I need the final table to be, dropping the source
    table, and creating it from scratch with createTable

    Not something I'd want to do in production of course, but then again I
    won't be using SQLite in production :)

    On Wed, Dec 9, 2015 at 10:01 AM, Mick Hansen [email protected]
    wrote:

    Likely not a problem with other dialects since they have actual schema
    change capabilities.
    SQLite does not allow schema changes, the only way to do it is to backup,
    new table, transfer data.
    Looks like there's a bug with the new table creation.

    —
    Reply to this email directly or view it on GitHub
    #5007 (comment)
    .

  3. sushantdhiman commented on Jan 10, 2017

    @sushantdhiman
    Contributor

    Moved 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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions