3
votes

I'm using Sequelize 2.0.0-rc3 and there's an error I'm encountering; it seems like I'm writing the migration correctly but I'm getting an error trying to run it. I'm using Postgresql on the backend. Everything seems to be working fine; this is a new, isolated issue. The Document table and id column exists (created it in a previous migration, but discovered it's not auto-incrementing id's; so tried creating this migration to add auto-incrementing).

var p = require('bluebird');

module.exports = {
    up: function (migration, DataTypes, done) {
        var promises = [];
        promises.push(
            migration.changeColumn(
                'Document',
                'id',
                {
                    type: DataTypes.INTEGER,
                    primaryKey: true,
                    autoIncrement: true,
                    allowNull: false
                }
            ));
        p.all(promises).then(done.bind(null, null)).catch(function (err) {
            console.error('Migration Failed: ', err);
            done(err);
        });

    },

    down: function (migration, DataTypes, done) {
        done();
    }
};

Possibly unhandled TypeError: Cannot call method 'push' of undefined at Object.module.exports.QueryGenerator.dataTypeMapping (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/lib/dialects/postgres/query-generator.js:848:32) at Object.module.exports.QueryGenerator.pgDataTypeMapping (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/lib/dialects/postgres/query-generator.js:843:19) at Object.module.exports.QueryGenerator.changeColumnQuery (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/lib/dialects/postgres/query-generator.js:250:31) at module.exports.QueryInterface.changeColumn (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/lib/query-interface.js:345:37) at module.exports.Migration.(anonymous function) [as changeColumn] (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/lib/migration.js:26:50) at /Users/csimpson/code/temp-cause-server/database/migrations/20141216000001-alter-id-increment.js:8:41 at tryCatch1 (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/node_modules/bluebird/js/main/util.js:45:21) at Promise$_callHandler [as _callHandler] (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:660:13) at Promise$_settlePromiseFromHandler [as _settlePromiseFromHandler] (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:675:18) at Promise$_settlePromiseAt (/Users/csimpson/code/temp-cause-server/node_modules/sequelize/node_modules/bluebird/js/main/promise.js:845:14)

1

1 Answers

0
votes

I ran into the Possibly unhandled TypeError: Cannot call method 'push' of undefined error as well. I was also trying to add an id field to an existing table, one I had created in the previous migration.

My fix had two parts:

1) Add unique: true to the id column.

2) Undo the previous migration (where I created the table that I want to add an id column to), and then run both migrations at once.

Until I did both of these, my migration attempts failed.