mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Create table if_not_exists=True argument, closes #397
This commit is contained in:
parent
79b5b58354
commit
aa24903113
3 changed files with 33 additions and 3 deletions
|
|
@ -522,7 +522,9 @@ This will create a table with the following schema:
|
|||
Explicitly creating a table
|
||||
---------------------------
|
||||
|
||||
You can directly create a new table without inserting any data into it using the ``.create()`` method::
|
||||
You can directly create a new table without inserting any data into it using the ``.create()`` method:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
db["cats"].create({
|
||||
"id": int,
|
||||
|
|
@ -534,6 +536,17 @@ The first argument here is a dictionary specifying the columns you would like to
|
|||
|
||||
This method takes optional arguments ``pk=``, ``column_order=``, ``foreign_keys=``, ``not_null=set()`` and ``defaults=dict()`` - explained below.
|
||||
|
||||
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``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
db["cats"].create({
|
||||
"id": int,
|
||||
"name": str,
|
||||
}, pk="id", if_not_exists=True)
|
||||
|
||||
.. _python_api_compound_primary_keys:
|
||||
|
||||
Compound primary keys
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue