From 80b5fa7f12fc1bc3a1f6dda14a7b54a0112a320d Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 22 Jul 2023 12:19:01 -0700 Subject: [PATCH] Documentation for replace=True/ignore=True, refs #568 --- docs/python-api.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/python-api.rst b/docs/python-api.rst index bb9ea5e..33a50ba 100644 --- a/docs/python-api.rst +++ b/docs/python-api.rst @@ -545,7 +545,7 @@ This method takes optional arguments ``pk=``, ``column_order=``, ``foreign_keys= A ``sqlite_utils.utils.sqlite3.OperationalError`` will be raised if a table of that name already exists. -To do nothing if the table already exists, add ``if_not_exists=True``: +You can pass ``ignore=True`` to ignore that error. You can also use ``if_not_exists=True`` to use the SQL ``CREATE TABLE IF NOT EXISTS`` pattern to achieve the same effect: .. code-block:: python @@ -554,6 +554,8 @@ To do nothing if the table already exists, add ``if_not_exists=True``: "name": str, }, pk="id", if_not_exists=True) +To drop and replace any existing table of that name, pass ``replace=True``. This is a **dangerous operation** that will result in loss of existing data in the table. + You can also pass ``transform=True`` to have any existing tables :ref:`transformed ` to match your new table specification. This is a **dangerous operation** as it will drop columns that are no longer listed in your call to ``.create()``, so be careful when running this. .. code-block:: python