4

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?

r.k
  • 97
  • 1
  • 2
  • 6

5 Answers5

7

https://github.com/sequelize/cli/blob/master/docs/FAQ.md

try

npx sequelize-cli model:generate --name user --attributes name:string,login_method:enum:'{email,google}'
Yumi Ko
  • 71
  • 1
  • 5
  • @AkashElhance What message do you see when you run the command? – Yumi Ko Jun 01 '21 at 00:02
  • ERROR: Attribute 'Status_Name:enum:'{Completed,Pending}'' cannot be parsed: Unknown type ''{Completed,Pending}'' – Akash Elhance Jun 02 '21 at 19:01
  • @AkashElhance I have tried ```npx sequelize-cli model:generate --name user --attributes name:string,login_method:enum:'{email,google}',Status_Name:enum:'{Completed,Pending}'``` and I don't see error – Yumi Ko Jun 30 '21 at 05:24
2

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'
briancollins081
  • 845
  • 9
  • 19
0

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 .

Arpit Vyas
  • 2,118
  • 1
  • 7
  • 18
0

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.

aum trivedi
  • 129
  • 4
0

npx sequelize-cli model:generate --name User --attributes username:string,email:string,password:string,role:ENUM("users","admin")

instead or writing this try this

npx sequelize-cli model:generate --name User --attributes username:string,email:string,password:string,role:enum:'{users,admin}'