mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-25 02:14:31 +02:00
Sanity check add_foreign_key() column exists, closes #29
This commit is contained in:
parent
364b0fb678
commit
976263effc
2 changed files with 11 additions and 0 deletions
|
|
@ -466,6 +466,9 @@ class Table:
|
|||
return pks[0].name
|
||||
|
||||
def add_foreign_key(self, column, other_table=None, other_column=None):
|
||||
# Ensure column exists
|
||||
if column not in self.columns_dict:
|
||||
raise AlterError("No such column: {}".format(column))
|
||||
# If other_table is not specified, attempt to guess it from the column
|
||||
if other_table is None:
|
||||
other_table = self.guess_foreign_table(column)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue