ask-your-database icon indicating copy to clipboard operation
ask-your-database copied to clipboard

Cannot read 'id' from property

Open aLearningProcess opened this issue 2 years ago • 2 comments

Hi, first ever GitHub issue being created, so please be kind: :)

I am a python programmer, so don't know Node or JS as much. I've run down the rabbit hole of trying to find solutions, but I don't know how to implement most of the suggestions to try them out.

https://stackoverflow.com/questions/67193689/node-js-typeerror-cannot-read-property-id-of-undefined

My Error: (node:116947) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'id' of undefined at /home/usaspending-gpt4/.npm/_npx/cda643d17fed3bae/node_modules/ask-your-database/dist/index.js:70:188 at Array.map () at /home/usaspending-gpt4/.npm/_npx/cda643d17fed3bae/node_modules/ask-your-database/dist/index.js:70:39 at Array.map () at main (/home/usaspending-gpt4/.npm/_npx/cda643d17fed3bae/node_modules/ask-your-database/dist/index.js:69:49) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:116947) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:116947) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

aLearningProcess avatar Apr 25 '23 21:04 aLearningProcess

That's probably going to be this bit of code. exampleRows[tableName][column.column_name]. It sounds like it doesn't have any example rows for your table. It looks like it grabs an example row for each table by querying the table here

  for (const tableName of Object.keys(tables)) {
    const exampleRow = await db(tableName).first();
    exampleRows[tableName] = exampleRow;
  }

So I suspect your table (or one of your tables, at least) is empty and you need to insert a row for this project to work.

egitto avatar Jun 14 '24 18:06 egitto

I find a solution to solve this problem,just change the code as below:

  for (const tableName of Object.keys(tables)) {
    const exampleRow = await db(tableName).first();
    exampleRows[tableName] = exampleRow || {};
  }

carlors avatar Nov 13 '24 03:11 carlors