Cannot add primary key with addColumn
- Dominant language
- JavaScript
- Stars
- 51
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
Some years ago this same issue came up in https://github.com/db-migrate/node-db-migrate/issues/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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.