Skip to content

bigincrements does not work with composite keys (MySQL) #5341

@davidf84

Description

@davidf84

Environment

Knex version: 2.3.0
Database + version: MySQL 5.7
OS: Windows

Bug

  1. bigincrements does not work with a composite primary key. This is because the ALTER table command run after the CREATE to add the auto_increment only runs when you define an "increments". Logic is missing for bigincrements.

  2. Example


// this works (using increments)
knex.schema.createTable("test_table", table => {
        table.primary(['userId', 'name']);
        table.increments('userId');
        table.string('name');
}


// OUTPUT
[
  {
    sql: 'create table `test_table` (`userId` int unsigned not null, `name` varchar(255), primary key (`userId`, `name`))',
    bindings: []
  },
  {
    sql: 'alter table `test_table` modify column `userId` int unsigned not null auto_increment',
    bindings: []
  }
]


// this does not work (using bigincrements)
knex.schema.createTable("test_table", table => {
        table.primary(['userId', 'name']);
        table.bigincrements('userId');
        table.string('name');
}

// OUTPUT - missing the alter table command
[
  {
    sql: 'create table `test_table` (`userId` bigint unsigned not null, `name` varchar(255), primary key (`userId`, `name`))',
    bindings: []
  }
]


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