r.k
r.k

Reputation: 97

Not able to create ENUM type attribute using sequelize cli

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?

Upvotes: 4

Views: 4114

Answers (5)

sunny yadav
sunny yadav

Reputation: 1

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}'

Upvotes: 0

Tarekkhaled
Tarekkhaled

Reputation: 21

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'

Upvotes: 2

Yumi Ko
Yumi Ko

Reputation: 61

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}'

Upvotes: 6

Aum Trivedi
Aum Trivedi

Reputation: 147

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.

Upvotes: 0

Arpit Vyas
Arpit Vyas

Reputation: 2227

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 .

Upvotes: 0

Related Questions