In this lesson, we'll describe foreign keys and how they can be used to establish relationships between entities in the database.
We'll add a new
User entity to the project and show how we can create a foreign key relationship between a
Task and a
User, so that a task can be assigned to a user.
We'll show how you can have the database perform an action when you delete one part of a foreign key relationship so that your database is always in a valid state.
Summary of Content:
- How to define a foreign key in the
- What problems we might have if we don't use a foreign key
- What referential integrity is and why it is important.
- Why we might see a
SqliteConstraintExceptionwhen deleting an entity, and how to fix it
- Defining an
onDeleteaction to be performed when a
- How we could delete
Taskswhen we delete their assigned
- How we could automatically unassign
Tasksfrom a deleted