From 0b702f3679a2ffd4e3efb5c34b9fe30221172ccb Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 17 Nov 2017 08:18:26 -0800 Subject: [PATCH] Fixed weird edge-case with foreign key detection It turns out it is possible for a SQLite table to define a foreign key relationship to a table that does not actually exist We should still be able to handle these databases. --- datasette/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/datasette/utils.py b/datasette/utils.py index 32721c94..f65e5ad8 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -219,6 +219,10 @@ def get_all_foreign_keys(conn): for info in infos: if info is not None: id, seq, table_name, from_, to_, on_update, on_delete, match = info + if table_name not in table_to_foreign_keys: + # Weird edge case where something refers to a table that does + # not actually exist + continue table_to_foreign_keys[table_name]['incoming'].append({ 'other_table': table, 'column': to_,