From e0cd430e8905324bb0c9143b3adc8ea5fcf60d99 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 2 Sep 2020 13:17:01 -0700 Subject: [PATCH] Docs for sqlite_utils.AlterError in add_foreign_keys() --- docs/python-api.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/python-api.rst b/docs/python-api.rst index 5860397..650e1ab 100644 --- a/docs/python-api.rst +++ b/docs/python-api.rst @@ -802,6 +802,8 @@ The ``table.add_foreign_key(column, other_table, other_column)`` method takes th - If the column is of format ``author_id``, look for tables called ``author`` or ``authors`` - If the column does not end in ``_id``, try looking for a table with the exact name of the column or that name with an added ``s`` +This method first checks that the specified foreign key references tables and columns that exist and does not clash with an existing foreign key. It will raise a ``sqlite_utils.AlterError`` exception if these checks fail. + .. _python_api_add_foreign_keys: Adding multiple foreign key constraints at once @@ -822,6 +824,8 @@ Here's an example adding two foreign keys at once: ("dogs", "home_town_id", "towns", "id") ]) +This method runs the same checks as ``.add_foreign_keys()`` and will raise ``sqlite_utils.AlterError`` if those checks fail. + .. _python_api_index_foreign_keys: Adding indexes for all foreign keys