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

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

Open
davidf84 opened this issue Oct 1, 2022 · 1 comment
Open

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

davidf84 opened this issue Oct 1, 2022 · 1 comment

Comments

@davidf84
Copy link
Contributor

davidf84 commented Oct 1, 2022

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: []
  }
]


davidf84 pushed a commit to davidf84/knex that referenced this issue Oct 2, 2022
kibertoad pushed a commit that referenced this issue Nov 29, 2023
… in MySQL - #5341 (#5343)

Co-authored-by: David Farrugia <david.farrugia@sagossgroup.com>
@kibertoad
Copy link
Collaborator

Released in 3.1.0

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

2 participants