Question

How can I check whether a field exists in my table, via sequelize orm. Note that I have already defined the full object model. I just need to check whether a particular field exists or not.

Was it helpful?

Solution

You can see what is inside your database via:

sequelize.getQueryInterface().describeTable('nameOfTableHere').success(function(data){})

If you want to check the table of a specific model you could also do this:

sequelize.getQueryInterface().describeTable(Model.tableName).success(function(data) {})

OTHER TIPS

Since I had already defined the object model, the following expression gives an array of field names defined in the model.

Object.keys(Model.rawAttributes)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top