Not able to create ENUM type attribute using sequelize cli

Viewed 2216

Trying to create a model that has an enum field with certain values using Sequelize CLI.

sequelize model:generate --name user --attributes name:string,login_method:enum('email','google')

Error: bash: syntax error near unexpected token `('

What is the right syntax to do so?

4 Answers

you can do it with

model:generate --name User --attributes 'login_method:enum:{google,facebook}'

Another good example is:

npx sequelize-cli model:generate --name devicelogs --attributes 'type:enum:{embedded,console,wearable,smarttv,browser,tablet,mobile}','browser:enum:{Chrome,Firefox,Safari,Opera,Internet Explorer,Edge,Edge Chromium,Yandex,Chromium,Mobile Safari,Samsung Browser}'

from sequelize-cli code you can also try

  • first_name:string,last_name:string,bio:text,role:enum:{Admin, 'Guest User'},reviews:array:string
  • 'first_name:string, last_name:string, bio:text, role:enum:{Admin, Guest User} reviews:array:string'

It should be possible to create enum values from model:create command

you can do like this .

$ sequelize model:create --name User --attributes opts:enum(x,y,z)

hope this help .

Try this one:

npx sequelize model:create --name User --attributes 'opts:enum:{x,y,z}'

Or

sequelize model:create --name User --attributes 'opts:enum:{x,y,z}'

Hope this will help you.

Related