2

In my MySQL database i have a JSON column that i created using the following sequelize-cli migration:

queryInterface.addColumn(
          'Users',
          'favorites',
          {
              type: Sequelize.JSON,
              allowNull: false,
              defaultValue: []
  }
      );

However, instead of having a default value of [], the records are getting a default value of null for that column.

What am i doing wrong?

Gambit2007
  • 3,260
  • 13
  • 46
  • 86

1 Answers1

1

In MySQL - you cant have default value for JSON field in case of strict mode.

Here you can get some explanation and solution to resolve this issue: Why can't a text column have a default value in MySQL?

Then you can use your code without any modification.