Skip to content

Cascaded table data is dropped on column add during migration #2584

@dominic-simplan

Description

@dominic-simplan

Issue type:

[x] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[x] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

I have a tableA which has ON CASCADE DELETE foreign key contstraint on tableB.
Now I add a column to tableB during a migration, and all data of tableA is gone, as the migration drops and recreates tableB:

await queryRunner.addColumn("Project", new TableColumn({
            name: "CustomVersion",
            type: "varchar",
            isNullable: true
        }));

query:  CREATE TABLE "temporary_Project" (...)
query:  INSERT INTO "temporary_Project"...
query:  DROP TABLE "Project"

Shouldn't the foreign key constraints be handled/disabled before dropping the table? Or am I doing it wrong?

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