Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ERROR: Failed to open the referenced table 'rol'

Aperta
#1,195 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sequelize/cli

Tutte le issue di sequelize/cli

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.