ERROR: Failed to open the referenced table 'rol'
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, mysql
- Lĩnh vực
- database
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- JavaScript
- Star
- 2.6k
- Fork
- 524
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của sequelize/cli
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
Tất cả issue của sequelize/cli
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Daemon passes --experimental-wasm-jspi unconditionally on Node >= 24; Node 26 rejects the flag Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Automattic/studio#4908 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
sugarlabs/musicblocks#8847 ·