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

190
Views
Secuela: restricciones de clave externa

Tengo un problema al deshacer mis migraciones usando sequelize-cli.

me sale este error:

 == 20211023095522-create-product: reverting ======= ERROR: Cannot delete or update a parent row: a foreign key constraint fails

Aquí está mi modelo:

 "use strict"; const { Model } = require("sequelize"); module.exports = (sequelize, DataTypes) => { class Product extends Model { /** * Helper method for defining associations. * This method is not a part of Sequelize lifecycle. * The `models/index` file will call this method automatically. */ static associate(models) { // define association here this.hasOne(models.ProductInfo, { foreignKey: "product_id", }); this.belongsToMany(models.Size, { through: "product_size", foreignKey: "product_id", }); this.belongsToMany(models.Category, { through: "product_category", foreignKey: "product_id", }); this.belongsToMany(models.Color, { through: "product_color", foreignKey: "product_id", }); } toJSON() { return { ...this.get(), updatedAt: undefined, }; } } Product.init( { stock: { type: DataTypes.INTEGER, defaultValue: 0, }, }, { sequelize, modelName: "Product", } ); return Product; };

Y aquí hay un modelo de producto asociado (todos están asociados de la misma manera):

 "use strict"; const { Model } = require("sequelize"); module.exports = (sequelize, DataTypes) => { class Size extends Model { static associate(models) { // define association here this.belongsToMany(models.Product, { through: "product_size", foreignKey: "size_id", }); } } Size.init( { name: { type: DataTypes.STRING, allowNull: false }, }, { sequelize, modelName: "Size", } ); return Size; };

Intenté agregar onDelete: "Cascade" y onUpdate: "CASCADE" en cada uno de mis parámetros de asociación, pero no resolvió mi problema.

¿Tienes alguna idea?

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!