Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite: "Cannot read property 'name' of undefined" when loading foreign keys of a table #9237

Closed
Obiwan1995 opened this issue Jul 25, 2022 · 0 comments · Fixed by #9238
Closed

Comments

@Obiwan1995
Copy link
Contributor

Obiwan1995 commented Jul 25, 2022

Issue Description

When loading foreign keys of a table, I get this error Cannot read property 'name' of undefined. It's because foreign keys mapping can't be found. I looked a bit deeper and found that the regex for foreign keys didn't match the CREATE TABLE sql because the regex expects a space between FOREIGN KEY and the list of columns.
As stated in SQLite documentation (https://www.sqlite.org/foreignkeys.html), the space is not mandatory:

CREATE TABLE track(
  trackid     INTEGER, 
  trackname   TEXT, 
  trackartist INTEGER,
  FOREIGN KEY(trackartist) REFERENCES artist(artistid)
);

I've tested the regex in the code on regex101.com with the example provided by SQLite and it does not match.

Expected Behavior

The regex should handle both space and no-space syntaxes and it should successfully match the CREATE TABLE sql to get the foreign keys.

Actual Behavior

Cannot read property 'name' of undefined / AbstractSQLiteQueryRunner.ts, line 1510.

Steps to Reproduce

  1. Create a table with the script above
  2. Call loadTable on it

My Environment

Dependency Version
Operating System Windows 10
Node.js version 16.15.1
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 yes
sqljs yes
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.
Obiwan1995 added a commit to Obiwan1995/typeorm that referenced this issue Jul 25, 2022
pleerock pushed a commit that referenced this issue Aug 24, 2022
Closes #9237

Co-authored-by: Brice Miclo <brice.miclo@socomec.com>
wirekang pushed a commit to wirekang/typeorm that referenced this issue Aug 25, 2022
…m#9238)

Closes typeorm#9237

Co-authored-by: Brice Miclo <brice.miclo@socomec.com>
nordinh pushed a commit to nordinh/typeorm that referenced this issue Aug 29, 2022
…m#9238)

Closes typeorm#9237

Co-authored-by: Brice Miclo <brice.miclo@socomec.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant