Skip to content

queryRunner.getTable() fails if Foreign Key is set in target table. #9266

@idenisovs

Description

@idenisovs

Issue Description

I try to run the simple data migration script, just like that

public async up(queryRunner: QueryRunner): Promise<void> {
    const registrationTable = await queryRunner.getTable('registration');
}

It fails with TypeError message: Cannot read properties of undefined (reading 'name')

DDL of registration table:

CREATE TABLE registration (
    id        INTEGER  PRIMARY KEY AUTOINCREMENT,
    time      DATETIME NOT NULL ON CONFLICT ROLLBACK,
    client_id INTEGER  REFERENCES test1 (id) ON DELETE CASCADE NOT NULL ON CONFLICT ROLLBACK
);

DDL of test1 table:

CREATE TABLE test1 (
    id    INTEGER PRIMARY KEY ON CONFLICT ROLLBACK AUTOINCREMENT,
    fname TEXT    UNIQUE ON CONFLICT ROLLBACK
);

In case if I remove the Foreign Key constraint from table registration then everything is ok!

Expected Behavior

The queryRunner should return the Table object.

Actual Behavior

The queryRunner fails with following message:

TypeError: Cannot read properties of undefined (reading 'name')
at /home/xxxxxProjects/xxxxxx/backend/node_modules/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts:1553:46
    at Array.map (<anonymous>)
    at /home/xxxxxx/Projects/xxxxxx/backend/node_modules/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts:1527:64
    at async Promise.all (index 0)
    at async SqliteQueryRunner.getTable (/home/xxxxxx/Projects/xxxxxx/backend/node_modules/src/query-runner/BaseQueryRunner.ts:143:29)

My Environment

Dependency Version
Operating System Ubuntu 22.04
Node.js version v16.15.0
Typescript version 4.7.4
TypeORM version 0.3.7

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite yes
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✅ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

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