ERROR: Failed to open the referenced table 'rol'
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, mysql
- Ambito
- database
Direzione di ricerca
Compare the table names and foreign-key reference in create-rols.js and create-users.js, then check the migration order. Rerun the migrations against MySQL and confirm that users is created with a foreign key referencing an existing table and that the migration completes without the referenced-table error.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What you are doing?
Hello everyone,
I am having problems with creating the tables in my DB, the relationship is one to one between rols and users, but it gives me failure to take the foreign key in the users table, the code of the migrations is the following:
create-rols.js
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('rols', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
nombre: {
type: Sequelize.STRING
},
code: {
type: Sequelize.STRING
},
status: {
type: Sequelize.BOOLEAN,
defaultValue:true,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('rols');
}
};
create-users.js
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
email: {
type: Sequelize.STRING
},
nif: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
status: {
type: Sequelize.BOOLEAN,
defaultValue:true
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
},
rol_id: {
type: Sequelize.INTEGER,
allowNull: false,
references:{
model:'rol',
key:'id'
}
},
}).then(() => queryInterface.addIndex('users', ['rol_id']));
},
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('users');
}
};
What do you expect to happen?
Create a foreign key field in my users table
What is actually happening?
ERROR: Failed to open the referenced table 'rol'
Dialect: mysql
Database version: lastVersion
Sequelize CLI version: 6.5.2
Sequelize version: 6.25.5
- Lingua principale
- JavaScript
- Stelle
- 2.6k
- Fork
- 524
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di sequelize/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Tutte le issue di sequelize/cli
Issue simili
-
area:ui bug effort:low incomplete model:light plan planner:gpt-6-1-sol
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue hacktoberfest size/small type/docs up-for-grabs
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Redo-San/RedoSan-Authenticity#511 ·
I maintainer di solito rispondono entro 1 giorno
-
help wanted python v9 cert scope: curriculum
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
freeCodeCamp/freeCodeCamp#70604 ·
I maintainer di solito rispondono entro 1 giorno
-
type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
RocketChat/Rocket.Chat#42543 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno