MySQL alter schema increments first ignored
Author: CelluleCreated Jan 18, 2022Updated Sep 23, 2026
LabelsNG_bug
Environment
Knex version: 0.95.15 Database + version: MySQL 5.7.12 OS: Windows
Bug
- Explain what kind of behaviour you are getting and how you think it should do
Using .first() in column builder after .increments is ignored, it should have been included
- Error message
No Errors, but column is created as the last column instead of the first
- Reduced test code, for example in https://npm.runkit.com/knex or if it needs real database connection to MySQL or PostgreSQL, then single file example which initializes needed data and demonstrates the problem.
export async function up(knex: Knex) {
// Add id column to table
const t = knex.schema.alterTable("table_name", (table) => {
table.increments("id").primary().first();
});
}Resulting statement is
alter table `procedure_blueprint_references` add `id` int unsigned not null auto_increment primary keyI was expecting
alter table `procedure_blueprint_references` add `id` int unsigned not null auto_increment primary key firstSource: knex/knex