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

832
Vistas
Sequelize migrations - add foreign key constraint issue

I need to remove the existing foreign key constraint on a column and add a new constraint with same name which refers to primary key of another table.

I am getting an error ERROR: Constraint type must be specified through options.type. Though I am providing constraint type in option's object as third parameter.

Below is the migration code for reference.

 async up(queryInterface, Sequelize){
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.removeConstraint(
        'shipments',
        'shipments_status_id_fkey',
        { transaction }
      );
      await queryInterface.addConstraint(
        'shipments',
        'status_id',
        {
          type: 'foreign key',
          name: 'shipments_status_id_fkey',
          references: {
            table: 'statuses',
            field: 'id'
          },
          transaction
        }
      );
      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Documentation here shows that options should be the second parameter to addConstraint function. https://sequelize.org/master/class/lib/dialects/abstract/query-interface.js~QueryInterface.html#instance-method-addConstraint

await queryInterface.addConstraint(
        'shipments',
        {
          type: 'foreign key',
          fields: ['status_id']
          name: 'shipments_status_id_fkey',
          references: {
            table: 'statuses',
            field: 'id'
          },
          transaction
        }
      );
over 4 years ago · Santiago Trujillo 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