mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-31 06:24:21 +02:00
add_foreign_key can now detect table and pk, refs #25
This commit is contained in:
parent
c2622ceabd
commit
d645032cfa
7 changed files with 100 additions and 13 deletions
|
|
@ -300,12 +300,16 @@ Adding foreign key constraints
|
|||
|
||||
The ``add-foreign-key`` command can be used to add new foreign key references to an existing table - something which SQLite's ``ALTER TABLE`` command does not support.
|
||||
|
||||
See :ref:`python_api_add_foreign_key` in the Python API documentation for further details and warnings (this could corrupt your database).
|
||||
|
||||
To add a foreign key constraint pointing the ``books.author_id`` column to ``authors.id`` in another table, do this::
|
||||
|
||||
$ sqlite-utils add-foreign-key books.db books author_id authors id
|
||||
|
||||
If you omit the other table and other column references ``sqlite-utils`` will attempt to guess them - so the above example could instead look like this::
|
||||
|
||||
$ sqlite-utils add-foreign-key books.db books author_id
|
||||
|
||||
See :ref:`python_api_add_foreign_key` in the Python API documentation for further details, including how the automatic table guessing mechanism works.
|
||||
|
||||
.. _cli_create_index:
|
||||
|
||||
Creating indexes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue