ignore=True argument for add_foreign_key, closes #112

Also --ignore for add-foreign-key command

Plus table.add_foreign_key(...) now returns self, allowing more chaining
This commit is contained in:
Simon Willison 2020-09-20 15:17:25 -07:00
commit e23eedb4ce
6 changed files with 48 additions and 9 deletions

View file

@ -858,6 +858,12 @@ The ``table.add_foreign_key(column, other_table, other_column)`` method takes th
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.db.AlterError`` exception if these checks fail.
To ignore the case where the key already exists, use ``ignore=True``:
.. code-block:: python
db["books"].add_foreign_key("author_id", "authors", "id", ignore=True)
.. _python_api_add_foreign_keys:
Adding multiple foreign key constraints at once