mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-27 04:14:30 +02:00
Better error message if table has no columns, closes #424
This commit is contained in:
parent
4433eafff7
commit
0e60f3c80c
2 changed files with 7 additions and 0 deletions
|
|
@ -768,6 +768,7 @@ class Database:
|
||||||
# Soundness check not_null, and defaults if provided
|
# Soundness check not_null, and defaults if provided
|
||||||
not_null = not_null or set()
|
not_null = not_null or set()
|
||||||
defaults = defaults or {}
|
defaults = defaults or {}
|
||||||
|
assert columns, "Tables must have at least one column"
|
||||||
assert all(
|
assert all(
|
||||||
n in columns for n in not_null
|
n in columns for n in not_null
|
||||||
), "not_null set {} includes items not in columns {}".format(
|
), "not_null set {} includes items not in columns {}".format(
|
||||||
|
|
|
||||||
|
|
@ -1149,3 +1149,9 @@ def test_create_if_not_exists(fresh_db):
|
||||||
fresh_db["t"].create({"id": int})
|
fresh_db["t"].create({"id": int})
|
||||||
# This should not
|
# This should not
|
||||||
fresh_db["t"].create({"id": int}, if_not_exists=True)
|
fresh_db["t"].create({"id": int}, if_not_exists=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_if_no_columns(fresh_db):
|
||||||
|
with pytest.raises(AssertionError) as error:
|
||||||
|
fresh_db["t"].create({})
|
||||||
|
assert error.value.args[0] == "Tables must have at least one column"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue