Group Group Group Group Group Group Group Group Group

Foreign Key constraint doesn't work with SQLite (Chapter 9)

Hi. I’m following the Acronyms tutorial from the book and everything’s great so far. I chose to use SQLite instead of PostgreSQL and I’m saving the database on file. The problem is that the foreign key constraint explained in chapter 9 is not working as expected: I can create an acronym (with a random UUID) even if there is no existing user.

@dree39 by default SQLite doesn’t support foreign key constraints (or at least enforce them). You can enable it with databases.enableForeignKeys(on: .sqlite) in configure.swift.

1 Like