#4943·knex

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

  1. 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

  1. Error message

No Errors, but column is created as the last column instead of the first

  1. 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.
typescript
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

sql
alter table `procedure_blueprint_references` add `id` int unsigned not null auto_increment primary key

I was expecting

sql
alter table `procedure_blueprint_references` add `id` int unsigned not null auto_increment primary key first