TypeError: Cannot read property 'all' of undefined
See original GitHub issueEnvironment
Knex version: 0.19.1 Database + version: PostgreSQL 11.4 OS: Antergos (Arch Linux)
Bug
- Explain what kind of behaviour you are getting and how you think it should do I wanted to run a migration in order to add a new column to a table. I have already added columns to a table successfully this way:
exports.up = function (knex, Promise) {
return Promise.all([
knex.schema.table("myTable", table => {
table.string("myColumn");
})
]);
};
exports.down = function (knex, Promise) {
return Promise.all([
knex.schema.table("myTable", table => {
table.dropColumn("myColumn");
})
]);
};
This time knex has thrown an error (see below). I’ve managed to run the migration successfully this way:
exports.up = function (knex, Promise) {
return knex.schema.table('myTable', function (table) {
table.string('myColumn');
})
};
exports.down = function (knex, Promise) {
return knex.schema.table('myTable', function (table) {
table.dropColumn('myColumn');
})
};
but I found it weird that suddenly the first method suddenly does not work.
- Error message
TypeError: Cannot read property 'all' of undefined
at Object.exports.up (/home/user/databases/config/migrations/20190727133408_add_columns_myTable.js:2:20)
at Object.current.then (/home/user/node_modules/knex/lib/migrate/Migrator.js:454:40)
at Object.tryCatcher (/home/user/node_modules/knex/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/user/node_modules/knex/node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (/home/user/node_modules/knex/node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromiseCtx (/home/user/node_modules/knex/node_modules/bluebird/js/release/promise.js:611:10)
at _drainQueueStep (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:142:12)
at _drainQueue (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
- Reduced test code, for example in https://npm.runkit.com/knex or if it needs real database connection to MySQL or PostgreSQL, then single file example which initializes needed data and demonstrates the problem.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >[SOLVED] Cannot Read Property of Undefined in JavaScript
The “cannot read property of undefined” error occurs when you attempt to access a property or method of a variable that is undefined...
Read more >Failed: Cannot read property 'all' of undefined - Stack Overflow
In version 4.0.0, the function protractor.promise.all is no longer present in the protractor.promise namespace:.
Read more >Uncaught TypeError : Cannot read properties of undefined
The root cause of the error is that the declared variable doesn't have any value, so by default, JavaScript treats all variables as...
Read more >How to Avoid the Infamous "Cannot read properties of ... - Bitovi
Interpreting undefined or null as subtypes of all other types can lead to runtime problems. For example, if you try to get the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The second argument
Promise
was removed in version 0.18.4: https://github.com/tgriesser/knex/commit/2ccaf3d7244f68bc3553e35ef49a2a2a53322496If you want to use
Promise.all
it is available natively in Node.js since version 0.12, so just remove the second argument to theup
anddown
functions:@Isanderthul instead of removing second argument, you could have as well done