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

Schema builder primary() with options object having constraintName generates incorrect sql #5175

Open
hannta opened this issue May 12, 2022 · 0 comments
Assignees

Comments

@hannta
Copy link

hannta commented May 12, 2022

Environment

Knex version: 2.0.0
Database + version: MariaDB 10.3.34
OS: Windows 11

Bug

Using schema builder primary() with options object having constraintName results incorrect sql.

Example:

await knex.schema.createTable('my_table', (table) => {
  table.string('column_a', 10).notNullable();
  table.string('column_b', 10).notNullable();
  table.primary(['column_a', 'column_b'], { constraintName: 'my_constraint' });
});

This gives error:

Error: create table `my_table` (`column_a` varchar(10) not null, `column_b` varchar(10) not null, constraint `my_constraint` as `constraintName` primary key (`column_a`, `column_b`)) default character set utf8mb4 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'as `constraintName` primary key (`column_a`, `column_b`)) default character s...' at line 1

If primary() is used giving constraint name as second parameter in plain string (table.primary(['column_a', 'column_b'], 'my_constraint')) this works. Though this is deprecated way of using the primary() at least based on TS typings.

This bug was introduced in knex version 1.0.3, I suspect this pr has the root cause #5017

@OlivierCavadenti OlivierCavadenti self-assigned this May 29, 2022
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