Questions tagged [sequelize-cli]

The Sequelize Command Line Interface (CLI) supports for migrations and seeders.

The Sequelize Command Line Interface (CLI) supports for migrations and seeders.

With migrations and seeders it's possible to transfer an existing database into another state and vice versa: those state transitions are saved in migration storage and seeder storage accordingly, which describe the way how to get to the new state and how to revert the changes in order to get back to the old state.

Useful links:


Related tags:

499 questions
84
votes
7 answers

Get only dataValues from Sequelize ORM

I'm using the sequelize ORM to fetch data from a PSQL DB. However, when I retrieve something, a whole bunch of data is given. The only data I want is inside 'dataValues'. Of course, I can use object.dataValues. But, is there any other good…
Gijo Varghese
  • 11,264
  • 22
  • 73
  • 122
76
votes
7 answers

How to Add, Delete new Columns in Sequelize CLI

I've just started using Sequelize and Sequelize CLI Since it's a development time, there are a frequent addition and deletion of columns. What the best the method to add a new column to an existing model? For example, I want to a new column…
Gijo Varghese
  • 11,264
  • 22
  • 73
  • 122
41
votes
13 answers

How to set primary key type to UUID via Sequelize CLI

I'm creating a DB model via Sequelize CLI with this command: sequelize model:create --name User --attributes "firstname:string, lastname:string" This creates the corresponding migration script: 'use strict'; module.exports = { up:…
rtorres
  • 2,601
  • 3
  • 27
  • 33
31
votes
9 answers

Set defaultValue to todays date in a Sequelize migration

I'm using Node Express with Sequelize and I want to set the defaultValue for the column "date" in the database to todays date. I tried with the following migration, but it didn't work, as it set the default date to be the same date as when I ran the…
Andreas
  • 2,287
  • 2
  • 23
  • 26
27
votes
1 answer

Revert Only One of Two Migrations in Sequelize-CLI?

If we created 2 new migration scripts and ran sequelize-cli db:migrate , both migration scripts will run. Both migrations are also reverted when we ran once the command sequelize-cli db:migrate:undo Question: Can we undo only the latest of the 2…
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
23
votes
1 answer

sequelize select and include another table alias

I'm using sequelize to acess a postgres database and I want to query for a city and for example include the "Building" table but I want to rename the output to "buildings" and return the http response but I have this error: {…
John
  • 1,697
  • 4
  • 27
  • 53
20
votes
1 answer

Composite primary key in Sequelize

Can someone suggest how do I set primary key on two columns within the same table. var relation = { 'user_id': { type: DataTypes.INTEGER }, 'organization_id':{ type: DataTypes.INTEGER } } I…
Anish
  • 745
  • 2
  • 8
  • 21
20
votes
5 answers

Run only the next migration file

Is it possible to run only the next migration file with the sequelize-cli? I have been looking through the docs and help-section of the cli, and it does not appear to be such a feature. For instance, I have the following when running the sequelize…
Automatico
  • 12,420
  • 9
  • 82
  • 110
18
votes
6 answers

How to add column in Sequelize existing model?

I have added a model and a migration file using this command node_modules/.bin/sequelize model:generate --name User --attributes firstName:string,lastName:string,email:string Now I wanted to add few more fields like gender and age in to the…
Ajay P.
  • 455
  • 1
  • 6
  • 14
17
votes
3 answers

Using sequelize-cli in Node 14 with type: module

I'm trying to set up the project using Node v14.3 and sequelize. I don't want to use babel-register. Instead of this I set "type": "module" in my package.json and use all ES6 - ES11 features out of the box. I also want to use sequelize-cli for…
Kasheftin
  • 7,509
  • 11
  • 41
  • 68
17
votes
4 answers

sequalize migration with dotenv

I am saving my database config in dotenv file. I am using sequelize migration which has a config.json file in config folder: { "development": { "username": "root", "password": null, "database": "test", "host": "127.0.0.1", …
Alvin
  • 8,219
  • 25
  • 96
  • 177
16
votes
2 answers

Migrations in Sequelize in my own folder structure

I am new to Sequelize and my current project requires me to use it with migrations. I am familiar with migrations what they do and how. I am coming from Django background where each sub app has modals, views, apis, urls and migrations in the same…
hannad rehman
  • 4,133
  • 3
  • 33
  • 55
16
votes
1 answer

How to create join table with foreign keys with sequelize or sequelize-cli

I'm creating models and migrations for two types, Player and Team that have many to many relationship. I'm using sequelize model:create, but don't see how to specify foreign keys or join tables. sequelize model:create --name Player --attributes…
1192805
  • 988
  • 2
  • 10
  • 26
15
votes
1 answer

Should Sequelize migrations update model files?

Are Sequelize migrations supposed to keep your model files in line with your database? I used the sequelize cli to bootstrap a simple project and create a model node_modules/.bin/sequelize model:generate --name User --attributes email:string. I…
Jeffrey Kandel
  • 410
  • 1
  • 4
  • 14
14
votes
3 answers

How to seed uuidv4 with sequelize

I am trying to seed a uuid using sequilize generateUUID but i get this error Seed file failed with error: sequelize.Utils.generateUUID is not a function TypeError: sequelize.Utils.generateUUID is not a function how do i seed a UUID? return…
WalksAway
  • 2,769
  • 2
  • 20
  • 42
1
2 3
33 34