Skip to content

Cannot add primary key with addColumn #31

Description

@brookiel

Some years ago this same issue came up in db-migrate/node-db-migrate#408. This was fixed by adding a check for a null options param:

    if (spec.primaryKey) {
      if (!options || options.emitPrimaryKey) {
        constraint.push('PRIMARY KEY');
      }
    }

A year later the call to createColumnDef from addColumn was changed to pass {} instead of null as options, which means this check always fails and the PRIMARY KEY constraint is never added. If you add an autoincrement field you are unable to set it as a primary key, resulting in the migration always failing with this error:

ER_WRONG_AUTO_KEY: Incorrect table definition; there can be only one auto column and it must be defined as a key

I have a PR to check for an empty object instead in the mysql adapter. This could be fixed upstream by changing the call to createColumnDef in db-migrate-base, but I'm hesitant to fix it there as other adapters don't seem to be having the issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions