Repository navigation
Closed
Labels
dialect: mssqlFor issues and PRs. Things that involve MSSQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue type
Description
What are you doing?
Creating a model with a boolean that has a defaultValue: false in MSSQL
isAdmin: { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false }What do you expect to happen?
When running the app with alter: true it should automatically update and alter tables requiring updates.
What is actually happening?
The line that it errors on is relating to the boolean field with a default value.
Executing (default): ALTER TABLE [solution_managers] ALTER COLUMN [isAdmin] BIT NOT NULL DEFAULT 0;
The error given by sequelize:
Unhandled rejection SequelizeDatabaseError: Incorrect syntax near the keyword 'DEFAULT'.
at Query.formatError (\node_modules\sequelize\lib\dialects\mssql\query.js:315:12)
at Request.connection.lib.Request [as userCallback] (\node_modules\sequelize\lib\dialects\mssql\query.js:107:25)
at Request.callback (\node_modules\tedious\lib\request.js:37:27)
at Connection.endOfMessageMarkerReceived (\node_modules\tedious\lib\connection.js:1880:20)
at Connection.dispatchEvent (\node_modules\tedious\lib\connection.js:997:36) at Parser.tokenStreamParser.on (\node_modules\tedious\lib\connection.js:827:14)
at Parser.emit (events.js:182:13)
at Parser.parser.on.token (\node_modules\tedious\lib\token\token-stream-parser.js:27:14)
at Parser.emit (events.js:182:13)
at addChunk (\node_modules\readable-stream\lib\_stream_readable.js:301:12)
at readableAddChunk (\node_modules\readable-stream\lib\_stream_readable.js:283:11)
at Parser.Readable.push (\node_modules\readable-stream\lib\_stream_readable.js:247:10)
at Parser.Transform.push (\node_modules\readable-stream\lib\_stream_transform.js:149:32)
at Parser.afterTransform (\node_modules\readable-stream\lib\_stream_transform.js:92:10)
at Parser._transform (\node_modules\tedious\lib\token\stream-parser.js:40:7) at Parser.Transform._read (\node_modules\readable-stream\lib\_stream_transform.js:185:10)
at Parser.Transform._write (\node_modules\readable-stream\lib\_stream_transform.js:173:83)
at doWrite (\node_modules\readable-stream\lib\_stream_writable.js:429:139)
at writeOrBuffer (\node_modules\readable-stream\lib\_stream_writable.js:418:5)
at Parser.Writable.write (\node_modules\readable-stream\lib\_stream_writable.js:327:11)
at Parser.addEndOfMessageMarker (\node_modules\tedious\lib\token\token-stream-parser.js:45:24)
at Connection.message (\node_modules\tedious\lib\connection.js:1869:32)Dialect: mssql
Dialect version: XXX
Database version: SQL SERVER 2016
Sequelize version: 4.41.0
Tested with latest release: 5.0.0-beta.13
Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.
Metadata
Metadata
Assignees
Labels
dialect: mssqlFor issues and PRs. Things that involve MSSQL (and do not involve all dialects).type: bugDEPRECATED: replace with the "bug" issue type
Activity
lyh2668 commentedon Nov 16, 2018
I found the same problem as you.
sushantdhiman commentedon Dec 1, 2018
May I get some SSCCE so this can be fixed, I wasn;t able to reproduce this
( What is SSCCE ? You can find template for Sequelize here )
A few good example of SSCCE
removeAttribute('id')results inundefined: nulldata value #7318 (comment)stale commentedon Mar 1, 2019
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
Taher62 commentedon Aug 2, 2019
Is this issue solved ?
I have the same problem
papb commentedon Aug 2, 2019
@Taher62 Please open a new bug report and fill the template.
dioncrs commentedon Jul 23, 2020
I encountered this problem here too, it occurs because he tries to change the default value of the column with "ALTER COLUMN" in my experience with MSSQL this is impossible to do this way. In MSSQL whenever a table with a default value is created, it adds a constraint for that value. I know it's a lot of work, so here where I work we never change the default value, my suggestion for developers is to remove the update from the default value of the query when using connection.sync ({alter: true}).
Useful link: https://stackoverflow.com/questions/15547210/modify-default-value-in-sql-server
Angrigo commentedon Mar 15, 2021
still an issue, any news?
"sequelize": "^6.5.0",
"sequelize-cli": "^6.2.0",
"tedious": "^9.2.3",
BevanLandoByte commentedon Sep 28, 2021
I am also experiencing the problem
"sequelize": "^6.6.5"
"tedious": "^11.0.7"
devtaha commentedon Nov 16, 2021
same problem I was facing
in my case I was running sync with force true while no tables were there in db
that why such error occurred for me
It might help someone.