You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I get:
I have an MsSql-table 'primary_table' in a non-standard schema called 'testSchema'.
The table has a non-nullable column 'id_not_nullable'.
I execute await knex.schema.withSchema("testSchema").table(tableName, (table) => { table.setNullable('id_not_nullable'); }); and it fails.
What it should do:
Above code removes the 'not_nullable'-flag in the table's column.
Error message: .setNullable: Column [id_not_nullable] does not exist in table [testSchema].[primary_table].
Reduced test code
const knex = require('knex')({
client: 'mssql',
connection: { // knex.js' mssql docker config
user: 'sa',
password: 'S0meVeryHardPassword',
server: 'localhost',
port: 21433,
database: 'knex_test',
}
});
const schemaName = "testSchema";
const tableName = "primary_table";
/**
* Prior to running create schema "testSchema" in DB (Knex doesn't support this for mssql)
* */
async function main() {
try {
await knex.schema.withSchema(schemaName).dropTable(tableName);
} catch {
// on first run this does not work because table does not exist.
}
await knex.schema.withSchema(schemaName).createTable(tableName, (table) => {
table.integer('id_nullable').nullable();
table.integer('id_not_nullable').notNull();
});
try {
const builder = knex.schema.withSchema("testSchema").table(tableName, (table) => {
table.setNullable('id_not_nullable');
});
const queries = await builder.generateDdlCommands();
console.log(queries);
await builder;
} catch (e) {
/**
* The error will say:
* .setNullable: Column [id_not_nullable] does not exist in table [testSchema].[primary_table].
*
* SetNullable does not work because the schema is actually not used in the resulting sql.
* @see tablecompiler.js -> _setNullableState, lin 318ff read:
*
* return this.client
* .queryBuilder()
* .from(this.tableNameRaw)
* .columnInfo(column)
*
* It should be including `.withSchema(this.schemaNameRaw)`:
*
* return this.client
* .queryBuilder()
* .withSchema(this.schemaNameRaw) // if schema is undefined, this does not hurt.
* .from(this.tableNameRaw)
* .columnInfo(column)
*
* which works.
* I will add a PR that does exactly this.
* Should also be a thing in all connections that do not implement their own _setNullableState
*/
console.log(e);
}
return 0;
}
main();
The text was updated successfully, but these errors were encountered:
Environment
Knex version: 3.1.0
Database + version: Mssql 2019-latest
OS: N/A
@smorey2
Bug
What I get:
I have an MsSql-table 'primary_table' in a non-standard schema called 'testSchema'.
The table has a non-nullable column 'id_not_nullable'.
I execute
await knex.schema.withSchema("testSchema").table(tableName, (table) => { table.setNullable('id_not_nullable'); });
and it fails.What it should do:
Above code removes the 'not_nullable'-flag in the table's column.
Error message:
.setNullable: Column [id_not_nullable] does not exist in table [testSchema].[primary_table].
Reduced test code
The text was updated successfully, but these errors were encountered: