Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
How to add additional attributes to a sequelize model after it has already been generated?

Is this possible or must the entire project be nuked and redone?

Example: I want to add a "breedId" column to a dogs table to reference model "Breeds"

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Dog', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.STRING(50),
        allowNull: false
      },
      description: {
        type: Sequelize.STRING
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Dog');
  }
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you appear to be using migrations, you will have a pretty easy time adding onto your tables.

Create another migration, and use queryInterface.addColumn(tableName: string, columnName: string, options: object) for the up, and queryInterface.removeColumn(tableName: string, columnName: string) for the down.

If you are using sequeilze.sync() to build your tables from the models, your options are worse. You either need to pass {force: true} into the .sync() method, which will drop the current tables before rebuilding them with the attributes in your models. Or, to preserve data you can omit {force: true} by manually adding the columns and foreign key constraints to the database, and add the corresponding attributes to the models.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!