You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cli.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1520,6 +1520,8 @@ You can specify foreign key relationships between the tables you are creating us
1520
1520
1521
1521
If a table with the same name already exists, you will get an error. You can choose to silently ignore this error with ``--ignore``, or you can replace the existing table with a new, empty table using ``--replace``.
1522
1522
1523
+
You can also pass ``--transform`` to transform the existing table to match the new schema. See :ref:`python_api_explicit_create` in the Python library documentation for details of how this option works.
Copy file name to clipboardExpand all lines: docs/python-api.rst
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -554,6 +554,25 @@ To do nothing if the table already exists, add ``if_not_exists=True``:
554
554
"name": str,
555
555
}, pk="id", if_not_exists=True)
556
556
557
+
You can also pass ``transform=True`` to have any existing tables :ref:`transformed <python_api_transform>` to match your new table specification. This is a **dangerous operation** as it may drop columns that are no longer listed in your call to ``.create()``, so be careful when running this.
558
+
559
+
.. code-block:: python
560
+
561
+
db["cats"].create({
562
+
"id": int,
563
+
"name": str,
564
+
"weight": float,
565
+
}, pk="id", transform=True)
566
+
567
+
The ``transform=True`` option will update the table schema if any of the following have changed:
568
+
569
+
- The specified columns or their types
570
+
- The specified primary key
571
+
- The order of the columns, defined using ``column_order=``
572
+
- The ``not_null=`` or ``defaults=`` arguments
573
+
574
+
Changes to ``foreign_keys=`` are not currently detected and applied by ``transform=True``.
0 commit comments