Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add primary key with addColumn #31

Open
brookiel opened this issue Aug 12, 2021 · 0 comments
Open

Cannot add primary key with addColumn #31

brookiel opened this issue Aug 12, 2021 · 0 comments

Comments

@brookiel
Copy link
Contributor

brookiel commented Aug 12, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant