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

835
Views
Secuela de migraciones: agregue un problema de restricción de clave externa

Necesito eliminar la restricción de clave externa existente en una columna y agregar una nueva restricción con el mismo nombre que se refiere a la clave principal de otra tabla.

Recibo un error ERROR: Constraint type must be specified through options.type . Aunque estoy proporcionando un tipo de restricción en el objeto de la opción como tercer parámetro.

A continuación se muestra el código de migración como referencia.

 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 answers
Answer question

0

La documentación aquí muestra que las opciones deben ser el segundo parámetro para la función addConstraint . 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 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!