Skip to content

alter doesn't change the default value correctly with MSSQL #14294

Description

@timhaak

Issue Creation Checklist

Bug Description

const { Model } = require('@sequelize/core');
module.exports = (sequelize, DataTypes) => {
  class SmsAccounts extends Model {
    static associate(models) {
    }
  }

  SmsAccounts.init(
    {
      expiresOn: {
        type: DataTypes.DATE,
        allowNull: false,
      },
      name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      portalId: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
      commodityClassification: {
        type: DataTypes.BOOLEAN,
        allowNull: false,
        defaultValue: false,
      },
      parentId: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
    },
    {
      sequelize,
      tableName: 'accounts',
      schema: process.env.SMS_SCHEMA,
      underscored: true,
    },
  );
  return SmsAccounts;
};
await sequelize.sync({ alter: true });

What do you expect to happen?

Update/create a table in mssql setting default values

What is actually happening?

Failing to set default value due to incorrect syntax.

Executing (default): ALTER TABLE [sms_test].[accounts] ALTER COLUMN [commodity_classification] BIT NOT NULL DEFAULT 0;
✖ Incorrect syntax near the keyword 'DEFAULT'.
✖ Error

Additional context

It should be doing something similar to the following

ALTER TABLE [sms_test].[accounts] ADD DEFAULT 0 FOR commodity_classification;

Environment

  • Sequelize version: @sequelize/[email protected] (Same is happening on [email protected])
  • Node.js version: v17.8.0
  • If TypeScript related: TypeScript version: N/A
  • Database & Version: MSSQL (Microsoft SQL Azure (RTM) - 12.0.2000.8 )
  • Connector library & Version: tedious (14.4.0)

Would you be willing to resolve this issue by submitting a Pull Request?

  • [x ] No, I don't have the time, although I believe I could do it if I had the time...
    (Will try possibly next month once I've put out some fires.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mssqlFor issues and PRs. Things that involve MSSQL (and do not involve all dialects).

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions