Supabase Cascade: Mastering Relational Data Deletion
Managing relational data in Supabase isn’t just about inserting rows—it’s also about deleting them intelligently. In this post, you'll learn how to implement cascade deletes using PostgreSQL's CASCADE clause within Supabase tables.


Baskaran Manimohan
Founder, CloseFuture
Jul 10, 2025
What is Supabase?
In a world increasingly driven by data, developers seek platforms that are powerful, scalable, and developer-friendly. Supabase is an open-source backend-as-a-service (BaaS) built on top of PostgreSQL, aiming to provide a Firebase alternative. It gives you instant APIs, authentication, real-time subscriptions, and more — all by just connecting to your PostgreSQL database.
Think of it as "PostgreSQL with batteries included." Supabase empowers teams to build full-stack applications faster, with less friction and better performance, thanks to the robust SQL database and modern tooling.
How Do We Delete Table Data in Supabase?
Deleting data in Supabase (or PostgreSQL, more broadly) is as simple as executing a SQL command or using Supabase's client libraries (like supabase-js
).
Example via SQL:
Example via Supabase JS:
This works fine when the table is standalone or has no dependencies. However, when the data is related to other tables — say, bookings linked to users or properties — deleting a row can have unintended consequences. That’s where ON DELETE rules come in.
How to Delete Data With Relationships?
Let’s say you have a basic real estate booking system with the following tables:
Table Schema Definition
Table | Columns | Notes | |
---|---|---|---|
|
| Primary table for users (hosts & guests) | |
|
| Each property is hosted by a user | |
|
| Each booking links a guest and property |
ERD (Entity Relationship Diagram)
Example Modal Table With Mock Data

Users
id | name |
---|---|
1 | Alice Host |
2 | Bob Guest |
3 | Charlie Guest |
Properties
id | title | host_id |
---|---|---|
10 | Ocean-view Condo | 1 |
11 | Mountain Retreat | 1 |
Bookings
id | property_id | guest_id |
---|---|---|
100 | 10 | 2 |
101 | 11 | 3 |
To delete data safely and consistently, especially in a relational schema like this, it's essential to define ON DELETE rules on foreign key constraints.
This leads us to the concept of Cascade behaviour in Supabase/PostgreSQL.
Exploring Cascade
Let’s dive into the types of ON DELETE
rules and their real-world implications.
CASCADE
Definition: When a row in the parent table is deleted, all matching rows in the child table are automatically deleted.
Example Scenario:
A host deletes their account. All their properties and the bookings related to those properties should also be deleted to maintain consistency.
Schema:
Outcome:
Delete user → their properties get deleted.
Properties deleted → bookings referencing them also get deleted.
Use With Caution: Can remove a large amount of data unintentionally.
RESTRICT
Definition: Prevents deletion of a row if it is referenced by any row in another table.
Example Scenario:
A guest has active bookings. Their account should not be deletable to avoid broken records.
Schema:
Outcome:
Trying to delete a guest with bookings results in an error.
Best For: Critical referential enforcement.
SET NULL
Definition: When a parent row is deleted, the referencing foreign key in the child table is set to NULL.
Example Scenario:
A host deletes their account, but you want to keep their property listings. The host reference becomes NULL.
Schema:
Outcome:
User deleted →
host_id
becomesNULL
inproperties
Note: Ensure host_id
column allows NULL values.
SET DEFAULT
Definition: When the parent is deleted, the child’s foreign key is set to a default value.
Example Scenario:
Have a placeholder user (e.g. ID 999
) representing "Deleted User". Use this as fallback reference.
Schema:
Outcome:
User deleted →
host_id
becomes999
Important: The default value must exist in the referenced table.
NO ACTION
Definition: Prevents deletion if referenced rows exist, but checks after the current transaction.
Example Scenario:
You're deleting multiple things — a user and their properties — within the same transaction. NO ACTION
allows all deletes to happen before throwing errors.
Schema:
Outcome:
Errors only if references still exist after transaction is complete.
Useful For: Complex transaction workflows.
NO ACTION INITIALLY DEFERRED
Definition: A deferred form of NO ACTION
where the foreign key constraint is checked at the end of the transaction, not immediately.
Example Scenario:
You're removing a user, their properties, and bookings in one transaction. Deferred checking allows full deletion sequencing.
Schema:
Outcome:
Constraint is only evaluated at
COMMIT
time.
Use When: You need advanced multi-step deletions.
Summary Table
Constraint Type | Behavior | Best Use Case |
---|---|---|
| Deletes child rows automatically | Auto-cleanup of related data |
| Prevents delete if child rows exist | Enforcing strict data integrity |
| Nullifies foreign key in child rows | Preserve data but remove relationships |
| Replaces FK with default value | Use a fallback entity for traceability |
| Delays delete check to transaction end | Multi-delete scenarios |
| Same as NO ACTION but deferred to commit | Advanced workflows with deferred constraint checking |
Final Thoughts
Understanding ON DELETE
actions is essential when building a robust Supabase (or PostgreSQL) application. Whether you're building a booking platform, a blog, or a social app — data integrity is key. Use cascading rules thoughtfully based on your application's needs.
Further Reading:
Stay tuned for more in-depth Supabase guides!
Related Blogs
Not just theory—real blogs, real use cases, real outcomes.

Bubble.io: no-code Drag & Drop App Builder!
CloseFuture has built 100+ apps and is still counting for clients using Bubble.io. These hands-on experiences, including obstacles, outputs & refinements, give us the advantage to share our insights and hard-won lessons that guide your incredible success path.

Baskaran Manimohan
Aug 19, 2025

FlutterFlow vs Flutter
FlutterFlow vs Flutter, both cater to app development for different purposes. Choose your best fit by relating your purpose to the right platform with the help of this fully comparative article.

Baskaran Manimohan
Aug 18, 2025

DreamFlow Explained: The Future of AI-Powered App Building
DreamFlow by FlutterFlow lets you turn your ideas into apps without writing a single line of code, but is that enough to make them market-ready?

Baskaran Manimohan
Aug 13, 2025