Skip to content

Cannot addColumn with a primaryKey on Postgres #408

@Nelspike

Description

@Nelspike

Hello!

After browsing the issues, I found a similar issue posted a couple of days ago (#407). However, this one's different, as it has to do with postgres (psql).

It seems that I cannot add a column while referencing it to be a primary key while using addColumn. To make matters more precise, the error is:

[ERROR] TypeError: Cannot read property 'emitPrimaryKey' of undefined
    at Class.Base.extend.createColumnConstraint (.../node_modules/db-migrate/lib/driver/pg.js:200:39)
    at Class.Base.extend.createColumnDef (.../node_modules/db-migrate/lib/driver/pg.js:29:31)
    at Class.module.exports.Class.extend.addColumn (.../node_modules/db-migrate/lib/driver/base.js:178:20)
    at exports.down (.../migrations/20160829085748-myMigration.js:16:8)
    at Migration._down (.../node_modules/db-migrate/lib/migration.js:176:34)

And the trace goes on. However, I debugged it a bit, and found the error to be the non-passing of objects, therefore resulting on the undefined. Step by step:

My migration:

db.addColumn('table_name', 'column_name', { type: type.STRING, primaryKey: true }, callback);

Where the error occurs:

if (spec.primaryKey && options.emitPrimaryKey) {

It would seem options are not passed here:

var def = this.createColumnDef(columnName, this.normalizeColumnSpec(columnSpec));

Therefore resulting on the undefined.

Keep up the good work, and cheers!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions