Home > Blockchain >  How to fix Sequelize auto character "s" in model
How to fix Sequelize auto character "s" in model

Time:12-31

I define models with Sequelize and Nodejs but key i define is:

var User = fsdb.define("user", {...})

and in my database I was create table have name the same: "user"

but when run sequelize run sql is:

'SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `users` AS `user`;'

so this show error

  original: Error: Table 'sql6587389.users' doesn't exist

how to fix it Thanks for any support

CodePudding user response:

You can use the freezeTableName option when defining your model. In your case it would look like this:

const User = fsdb.define("user", {...}, { freezeTableName: true });

From the linked documentation:

You can stop the auto-pluralization performed by Sequelize using the freezeTableName: true option. This way, Sequelize will infer the table name to be equal to the model name, without any modifications:

  • Related