Foreign key by default is null
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- sqlite, typescript
- Lĩnh vực
- documentation
Hướng nghiên cứu
Start with the associations documentation at the linked URL and verify how hasMany defines the foreign key and its allowNull behavior. Done means the page clearly documents the default behavior and the explicit configuration needed when a non-null foreign key constraint is intended.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Issue Description
I was going through the association docs to create foreign key constraints for my tables in sqlite but i noticed when using Model.HasMany(Child) by default the foreign key definition is allowNull: true which defeats the purpose of using a foreign key constraint.
https://sequelize.org/docs/v6/core-concepts/assocs/
Im not sure if i missed anything but i couldnt find this anywhere in the docs and the associations docs doesnt explain this behavior properly.
Let me know if i'm missing anything
Additional context
This code would define the foreign key employeeId with allowNull:true
sequelize.define("Employees", {
id: {
type: DataTypes.UUIDV4,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false
},
employeeType: {
type: DataTypes.INTEGER,
allowNull: false
}
}, {
indexes: [
{
using: "BTREE",
fields: ["employeeType"]
}
]
})
sequelize.define("Missions", {
id: {
type: DataTypes.UUIDV4,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
hours: {
type: DataTypes.INTEGER,
allowNull: false
},
missionName: {
type: DataTypes.STRING,
allowNull: true
},
missionDate: {
type: DataTypes.DATE,
allowNull: false
},
missionType: {
type: DataTypes.INTEGER,
allowNull: true
}
}
);
// 1 to many relationship between employees & missions
sequelize.models.Employees.hasMany(sequelize.models.Missions);
I had to refactor the code to this for the foreign key constraint to be effective
sequelize.define("Employees", {
id: {
type: DataTypes.UUIDV4,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false
},
employeeType: {
type: DataTypes.INTEGER,
allowNull: false
}
}, {
indexes: [
{
using: "BTREE",
fields: ["employeeType"]
}
]
})
sequelize.define("Missions", {
id: {
type: DataTypes.UUIDV4,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
employeeId: {
type: DataTypes.UUIDV4,
allowNull: false,
},
hours: {
type: DataTypes.INTEGER,
allowNull: false
},
missionName: {
type: DataTypes.STRING,
allowNull: true
},
missionDate: {
type: DataTypes.DATE,
allowNull: false
},
missionType: {
type: DataTypes.INTEGER,
allowNull: true
}
}
);
// 1 to many relationship between employees & missions
sequelize.models.Employees.hasMany(sequelize.models.Missions, {
foreignKey: 'employeeId',
as: 'missions'
});
- Ngôn ngữ chính
- HTML
- Star
- 30
- Fork
- 171
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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/website
-
docs: Managed Postgres callout + optional Appwrite link on postgres.mdx?Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 74/100
-
Update Migration.mdĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Error: Only HasMany associations support include.separateCó thể làm lại được @SippieCup đã nhận 199 ngày trước và không có pull request nào đang mở. Đang mở
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
Tất cả issue của sequelize/website
Issue tương tự
-
fix formatting of the sample database page of the docsCó thể đã có người làm @Aaqibhafeezkhan đã nhận hôm nay. Đang mởdocumentation good first issue help wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
chaoss/CollectOSS#544 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs: clarify gh api -f vs -F and @-file expansion in the gh skillCó thể đã có người làm @MatiasOlivera đã nhận hôm nay. Đang mởenhancement
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
ibm-granite/granite.build#504 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Say in the changelog that the text-index update cannot be rolled backCó thể đã có người làm @praetorianer777 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
praetorianer777/GoTome#275 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug untriaged
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
opensearch-project/search-relevance#618 ·
Maintainer thường phản hồi trong vòng 3 ngày