mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-09 18:14:09 +02:00
Ability to add a column that is a foreign key reference
Python API:
db["dogs"].add_column("species_id", fk="species")
# or
db["dogs"].add_column("species_id", fk="species", fk_col="ref")
CLI:
$ sqlite-utils add-column mydb.db dogs species_id --fk species
# or
$ sqlite-utils add-column mydb.db dogs species_id --fk species --fk-col ref
Closes #16
This commit is contained in:
parent
00c5a49a87
commit
50e2f94b58
6 changed files with 118 additions and 6 deletions
10
docs/cli.rst
10
docs/cli.rst
|
|
@ -266,6 +266,16 @@ You can add a column using the ``add-column`` command::
|
|||
|
||||
The last argument here is the type of the column to be created. You can use one of ``text``, ``integer``, ``float`` or ``blob``. If you leave it off, ``text`` will be used.
|
||||
|
||||
You can add a column that is a foreign key reference to another table using the ``--fk`` option::
|
||||
|
||||
$ sqlite-utils add-column mydb.db dogs species_id --fk species
|
||||
|
||||
This will automatically detect the name of the primary key on the species table and use that (and its type) for the new column.
|
||||
|
||||
You can explicitly specify the column you wish to reference using ``--fk-col``::
|
||||
|
||||
$ sqlite-utils add-column mydb.db dogs species_id --fk species --fk-col ref
|
||||
|
||||
.. _cli_add_column_alter:
|
||||
|
||||
Adding columns automatically on insert/update
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue