Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

831
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda