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?

5 Answers 5

6

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}'
Sign up to request clarification or add additional context in comments.

3 Comments

@AkashElhance What message do you see when you run the command?
ERROR: Attribute 'Status_Name:enum:'{Completed,Pending}'' cannot be parsed: Unknown type ''{Completed,Pending}''
@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
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'

Comments

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 .

1 Comment

@RAJKIRANSINGH is this helped you ?
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.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.