Skip to content

BUG: Database Integrity Issues - Foreign Key Constraints Not Enforced #571

@Hemil36

Description

@Hemil36

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

Description

SQLite disables foreign key constraints by default, meaning all foreign key rules (such as ON DELETE CASCADE and ON DELETE SET NULL) are ignored unless explicitly enabled.

Several database functions directly call:

conn = sqlite3.connect(DATABASE_PATH)

without running:

PRAGMA foreign_keys = ON;

As a result, foreign key relationships are silently ignored, and the database accepts invalid references.

If the foreign key enforcement remains disabled:

  • Data integrity will continue degrading silently.
  • Cascading deletes and SET NULL behaviors will never trigger.
  • The database will accumulate orphaned and invalid records.
  • JOIN queries and application logic relying on relationships will fail or produce incorrect results.
  • Over time, the application data becomes irrecoverably inconsistent, potentially requiring full data cleanup or migration.

Record

  • I agree to follow this project's Code of Conduct

Checklist before Submitting

  • Have you updated docs for it?
  • Have you added unit tests?
  • Have you made sure unit tests pass?
  • Have you made sure code formatting is correct?
  • Do Your changes passes all tests?

Metadata

Metadata

Assignees

Labels

backendbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions