SQLite Forum

Bug?: CREATE TABLE with unsatisfied FK and DROP TABLE results in Error
Login
Thanks Kees for the reply. PRAGMA foreign_keys are on, that is intended.

The problem here is, that I cannot DROP TABLEs which are empty. It does not happen in all circumstances, only in certain combinations of table and columns and foreign keys. So, sometimes you can DROP a table referencing, sometimes not.

Look at this complete example, starting with an empty DB.

```
➜  sqlite-tools-osx-x86-3310100 cat script.sql
PRAGMA foreign_keys;

CREATE TABLE "table" (
  "id"              INTEGER PRIMARY KEY AUTOINCREMENT
);

CREATE TABLE "column" (
  "id"              INTEGER PRIMARY KEY AUTOINCREMENT,

  "other_table_id"  INTEGER,
  "other_column_id" INTEGER,

  FOREIGN KEY (other_table_id) REFERENCES "table" (id) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (other_column_id) REFERENCES "column" (id) ON DELETE CASCADE ON UPDATE CASCADE
);

DROP TABLE "table";
DROP TABLE "column";
➜  sqlite-tools-osx-x86-3310100 rm test.db && ./sqlite3 test.db < script.sql
foreign_keys
------------
1           
Error: near line 18: no such table: main.table
➜  sqlite-tools-osx-x86-3310100 
```