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

242
Views
No se puede agregar una restricción de clave externa usando Sequelize

Intento crear una lista de tareas pendientes con Sequelize, pero siempre tengo este error: "No se puede agregar una restricción de clave externa usando Sequelize". Incluso buscando algunas pistas en StackOverflow, ¿alguien puede ayudar?

Migración de tareas pendientes

 module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable('Todos', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, description: { type: Sequelize.STRING, allowNull: false, }, createdAt: { allowNull: false, type: Sequelize.DATE, }, status_id: { type: Sequelize.INTEGER, allowNull: false, references: { model: 'Statuses', key: 'id', }, }, }); }, async down(queryInterface) { await queryInterface.dropTable('Todos'); }, };

Migración de estado

 module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable('Statuses', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER, }, name: { type: Sequelize.STRING, allowNull: false, }, }); }, async down(queryInterface) { await queryInterface.dropTable('Statuses'); }, }; Relationship in models
 // Status model Status.associate = (models) => { Status.belongsTo(models.Todo, { foreignKey: 'status_id', as: 'todo' }); }; // Todo model Todo.associate = (models) => { Todo.hasMany(models.Status, { foreignKey: 'status_id', as: 'statuses' }); };

¡Si alguien tiene alguna idea, se lo agradezco mucho! Gracias

about 4 years ago · Juan Pablo Isaza
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!