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

201
Views
Sqlite La falta de coincidencia de la clave externa sigue la migración

Mi solicitud de SQL falla cuando intento insertar datos en mi tabla PostVotes . Utilizo la migración de secuencias para migrar mi base de datos y tengo el mismo problema cuando hago mi solicitud de SQL en mi consola.

sequelize db:migrate

Cuando uso sequelize.sync() no tengo este problema

Mi mesa:

 /* TABLE Users */ queryInterface.createTable('Users', { id: { allowNull: false, primaryKey: true, type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, }, password: { type: Sequelize.STRING, allowNull: false, }, email: { type: Sequelize.STRING, allowNull: false, unique: true, }, }), queryInterface.createTable('Posts', { id: { allowNull: false, primaryKey: true, type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, }, title: { type: Sequelize.STRING, allowNull: false, }, userId: { type: Sequelize.UUID, primaryKey: true, onDelete: 'CASCADE', references: { model: 'Users', key: 'id', }, }, }), /* Table posts votes*/ queryInterface.createTable('PostVotes', { id: { allowNull: false, primaryKey: true, type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, }, vote: { // eslint-disable-next-line new-cap type: Sequelize.ENUM('up', 'down'), validate: { isIn: [['up', 'down']], }, allowNull: false, }, userId: { type: Sequelize.UUID, primaryKey: true, onDelete: 'CASCADE', references: { model: 'Users', key: 'id', }, }, postId: { type: Sequelize.UUID, primaryKey: true, onDelete: 'CASCADE', references: { model: 'Posts', key: 'id', }, }, }),

[Error: SQLITE_ERROR: discrepancia de clave externa: "PostVotes" hace referencia a "Publicaciones"]

Ya encontré la respuesta, pero nada funciona. Creo que mi error está en la tabla PostVotes pero no entiendo cuál.

Gracias !

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

ARREGLAR

 queryInterface.createTable('Posts', { id: { allowNull: false, primaryKey: true, type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, }, title: { type: Sequelize.STRING, allowNull: false, }, userId: { type: Sequelize.UUID, primaryKey: true, # DELETE THIS ONE onDelete: 'CASCADE', references: { model: 'Users', key: 'id', }, },

}),

Elimino la clave principal en la tabla Publicar columna ID de usuario

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