Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
How to force Sequelize Model.init to work?

I'm trying to initialize database table according model, but table can't be created, and there is no any errors. Furthermore, after this action, sequelize.models object has AccountsModel.

import { DataTypes, Model, Sequelize } from 'sequelize'
import { DatabaseConfig } from '../../database/config'

export class AccountsModel extends Model { }

export function initializeAccountsModel (sequelize: Sequelize): void {
    AccountsModel.init({
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true,
        },
        email: {
            type: DataTypes.STRING,
            allowNull: false,
        },
    }, {
        sequelize,
        tableName: DatabaseConfig.TABLE_NAMES.Accounts,
    })   
}

Model.sync() method is working, but I'm gonna follow OOP.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The .sync() method is the action that actually creates the tables when you start your application. It goes into your models directory and builds the tables based on the attributes you've specified in the individual models. If you don't run .sync(), this action will not occur.

If you wish to not use .sync(), the alternative is to either manually create the tables (Not great if you ever need to re-deploy for some reason), or utilize migrations.

Another important note regarding .sync() is that it will use the SQL query CREATE TABLE IF NOT EXISTS when building from the models, so if you have added attributes to the model in between syncs, these new columns will not be added to the table when you re-sync. You can bypass this by passing {force: true} into .sync(), but that will first DROP the table and then CREATE it again, causing data loss.

Migrations are strongly recommended for production applications.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda