Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I define Sequelize.STRING length?

I want to define a length of a datatype in sequelize. There is my source code :

var Profile = sequelize.define('profile', {   public_id: Sequelize.STRING,   label: Sequelize.STRING }) 

It create a table profiles with a public_id with a datatype varchar(255).

I would like to define a public_id with varchar(32).

I searched on the doc and the stack but couldn't find any answer...

How can I do that please ?

like image 411
gusera2334967 Avatar asked Apr 30 '13 08:04

gusera2334967


People also ask

How do you define varchar in Sequelize?

If you give the datatype as TEXT in Sequelize It will automatically convert that field to NVARCHAR(MAX ) for SQL Server database. But it is mentioned in Sequelize github repository from line 79 to 90. Show activity on this post. postgres supports Upto 1G for BOTH TEXT AND VARCHAR.

How do you define a model in Sequelize?

Models can be defined in two equivalent ways in Sequelize: Calling sequelize. define(modelName, attributes, options) Extending Model and calling init(attributes, options)

How do I set default value in Sequelize?

When you create a Sequelize model, you can add the default value for your model by adding the defaultValue option to the column(s) definition. The defaultValue option will be used by Sequelize to define default value(s) for your SQL column(s) when you create a table using Sequelize.


1 Answers

As it is mentioned in the documentation, use:

Sequelize.STRING(32)  
like image 153
Szymon Wygnański Avatar answered Oct 13 '22 11:10

Szymon Wygnański