Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize Error on DataTypes.ARRAY(DataTypes.STRING)

I am new to NodeJs development I am using NodeJs with mysql and Sequelize to create a Batch model with these properties.

const Batch = sequelize.define(
  "Batch",
  {
    title: { type: DataTypes.STRING, allowNull: false },
    studentIds: { type: DataTypes.STRING },
    teacherId: { type: DataTypes.STRING, allowNull: true }
  },
  {
    timestamps: false
  }
);

On async method call it is working fine.

Batch.sync().then((res) => {
  console.log("Batch model sync : ", Batch === sequelize.models.Batch);
});

But I need to change

studentIds: { type: DataTypes.ARRAY(DataTypes.STRING)}

Whenever I make this change it gives error

enter image description here

I am using node 14.5.0 MySql 8.0.21 and Sequelize 6.3.4

like image 428
Atif Zia Avatar asked Sep 19 '25 18:09

Atif Zia


1 Answers

DataTypes.ARRAY is not available on Mysql, it's only available on postgres.

Check in official docs: https://sequelize.org/api/v6/class/src/data-types.js~array

like image 81
Eduard Avatar answered Sep 21 '25 08:09

Eduard