Docs for /db/-/create alter: true option, refs #2101

This commit is contained in:
Simon Willison 2024-02-08 12:33:41 -08:00
commit 574687834f

View file

@ -844,9 +844,12 @@ The JSON here describes the table that will be created:
If the primary key is an integer column, it will be configured to automatically increment for each new record. If the primary key is an integer column, it will be configured to automatically increment for each new record.
If you set this to ``id`` without including an ``id`` column in the list of ``columns``, Datasette will create an integer ID column for you. If you set this to ``id`` without including an ``id`` column in the list of ``columns``, Datasette will create an auto-incrementing integer ID column for you.
* ``pks`` can be used instead of ``pk`` to create a compound primary key. It should be a JSON list of column names to use in that primary key. * ``pks`` can be used instead of ``pk`` to create a compound primary key. It should be a JSON list of column names to use in that primary key.
* ``ignore`` can be set to ``true`` to ignore existing rows by primary key if the table already exists.
* ``replace`` can be set to ``true`` to replace existing rows by primary key if the table already exists.
* ``alter`` can be set to ``true`` if you want to automatically add any missing columns to the table. This requires the :ref:`permissions_alter_table` permission.
If the table is successfully created this will return a ``201`` status code and the following response: If the table is successfully created this will return a ``201`` status code and the following response:
@ -925,6 +928,8 @@ You can avoid this error by passing the same ``"ignore": true`` or ``"replace":
To use the ``"replace": true`` option you will also need the :ref:`permissions_update_row` permission. To use the ``"replace": true`` option you will also need the :ref:`permissions_update_row` permission.
Pass ``"alter": true`` to automatically add any missing columns to the existing table that are present in the rows you are submitting. This requires the :ref:`permissions_alter_table` permission.
.. _TableDropView: .. _TableDropView:
Dropping tables Dropping tables