question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'Type' of undefined in tablecompiler.js

See original GitHub issue

knex 0.13.0

> looop@0.0.5 migrate /home/capaj/git_projects/looop/project-alpha/back-end
> babel-node node_modules/.bin/knex migrate:latest

  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=1 available=0 +0ms
  knex:client acquired connection from pool: __knexUid1 +9ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=1 +1ms
  knex:query show tables like ? +1ms
  knex:bindings [ 'knex_migrations' ] +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=2 +3ms
  knex:client releasing connection to pool: __knexUid1 +2ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=3 +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=1 available=3 +0ms
  knex:client acquired connection from pool: __knexUid2 +0ms
  knex:query show tables like ? +1ms
  knex:bindings [ 'knex_migrations_lock' ] +0ms
  knex:client releasing connection to pool: __knexUid2 +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=3 +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=1 available=3 +1ms
  knex:client acquired connection from pool: __knexUid3 +0ms
  knex:query select * from `knex_migrations_lock` +1ms
  knex:bindings [] +1ms
  knex:client releasing connection to pool: __knexUid3 +1ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=3 +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=1 available=3 +0ms
  knex:client acquired connection from pool: __knexUid1 +0ms
  knex:query select `name` from `knex_migrations` order by `id` asc +1ms
  knex:bindings [] +0ms
  knex:client releasing connection to pool: __knexUid1 +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=3 +0ms
  knex:tx trx4: Starting top level transaction +66ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=1 available=3 +0ms
  knex:client acquired connection from pool: __knexUid2 +0ms
  knex:query BEGIN; +1ms
  knex:bindings undefined +1ms
  knex:query select * from `knex_migrations_lock` for update +1ms
  knex:bindings [] +0ms
  knex:pool INFO pool mysql:mysql:client1 - dispense() clients=0 available=1 +1ms
  knex:query update `knex_migrations_lock` set `is_locked` = ? +1ms
  knex:bindings [ 1 ] +0ms
  knex:pool INFO pool mysql:mysql:client1 - dispense() clients=0 available=2 +0ms
  knex:query show tables like ? +1ms
  knex:bindings [ 'knex_migrations' ] +0ms
  knex:query show tables like ? +0ms
  knex:bindings [ 'knex_migrations_lock' ] +1ms
  knex:query select * from `knex_migrations_lock` +0ms
  knex:bindings [] +0ms
  knex:query select `name` from `knex_migrations` order by `id` asc +1ms
  knex:bindings [] +0ms
  knex:query select max(`batch`) as `max_batch` from `knex_migrations` +2ms
  knex:bindings [] +0ms
  knex:pool INFO pool mysql:mysql:client1 - dispense() clients=1 available=2 +1ms
  knex:client acquired connection from pool: __knexUid5 +0ms
  knex:query drop table if exists `application_error_log` +1ms
  knex:bindings [] +0ms
  knex:client releasing connection to pool: __knexUid5 +0ms
  knex:pool INFO pool mysql:mysql:client1 - dispense() clients=0 available=2 +0ms
  knex:pool INFO pool mysql:mysql:client1 - dispense() clients=1 available=2 +0ms
  knex:client acquired connection from pool: __knexUid6 +0ms
  knex:query alter table `events` add `organisation_id` int, add `deleted_at` datetime, add `is_discoverable` boolean default '1' +3ms
  knex:bindings [] +0ms
  knex:query show fields from `events` where field = ? +101ms
  knex:bindings [ 'author' ] +0ms
  knex:query SELECT KCU.CONSTRAINT_NAME, KCU.TABLE_NAME, KCU.COLUMN_NAME,        KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME,        RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC        USING(CONSTRAINT_NAME)WHERE KCU.REFERENCED_TABLE_NAME = ?   AND KCU.CONSTRAINT_SCHEMA = ?   AND RC.CONSTRAINT_SCHEMA = ? +1ms
  knex:bindings [ 'events', 'looop', 'looop' ] +0ms
  knex:client releasing connection to pool: __knexUid6 +7ms
  knex:pool INFO pool mysql:mysql:client1 - dispense() clients=0 available=2 +0ms
Knex:warning - migrations failed with error: Cannot read property 'Type' of undefined
  knex:query update `knex_migrations_lock` set `is_locked` = ? +0ms
  knex:bindings [ 0 ] +0ms
  knex:query ROLLBACK; +1ms
  knex:bindings undefined +0ms
  knex:tx trx4: releasing connection +7ms
  knex:client releasing connection to pool: __knexUid2 +0ms
  knex:pool INFO pool mysql:mysql:client0 - dispense() clients=0 available=3 +0ms
TypeError: Cannot read property 'Type' of undefined
    at /home/capaj/git_projects/looop/project-alpha/back-end/node_modules/knex/lib/dialects/mysql/schema/tablecompiler.js:106:83
    at tryCatcher (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/promise.js:606:10)
    at Async._drainQueue (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/async.js:138:12)
    at Async._drainQueues (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/capaj/git_projects/looop/project-alpha/back-end/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:800:20)
    at tryOnImmediate (timers.js:762:5)
    at processImmediate [as _immediateCallback] (timers.js:733:5)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
elhigucommented, Jul 24, 2017

@wubzz could it be tested already when knex see that the column was not found

//Old
const column = resp[0];

//New
const column = resp[0];
if (!column) { 
  throw new Error(`Column ${colName} does not exist.`);
}

I don’t see a reason to even try to make the final query in this case.

2reactions
elhigucommented, Jul 24, 2017

@wubzz because IMO it makes more sense to get error of missing column name than just getting DB error that some query is trying to set destination column to type to undefined.

User probably will have even harder time to figure out why it fails. To help user even more maybe throw new Error(`Could not get column info of ${colName} for rename it to ${newColName}.`); will be more clear than just saying that col does not exist.

Edit: And type check falls to knex responsibility, because knex is the one who decided to make multiple queries to fullfil the operation requested by the user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JS error: Uncaught TypeError: Cannot read property 'type' of ...
You are trying to access dataset on array of HTML elements, whereas the dataset is defined on each element and not array. Instead...
Read more >
TypeError: Cannot read property 'type' of undefined is ...
This issue happens when the field used in one of your onSubmit Client Scripts is not present on the form view. Cause. Check...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Cannot read property 'type' of undefined" error message
HTML Message Type Input File Line Notes Created at JavaScript $(document).ready( function () { var table = $('#table_id').DataTable({ "dom":
Read more >
How to Fix TypeError: Cannot read Property 'push' of ...
Calling the method on a variable that was previously set to undefined. When working with variables and data types like strings, we tend...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found