Skip to content

Commit 0e60f3c

Browse files
committed
Better error message if table has no columns, closes #424
1 parent 4433eaf commit 0e60f3c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

sqlite_utils/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ def create_table_sql(
768768
# Soundness check not_null, and defaults if provided
769769
not_null = not_null or set()
770770
defaults = defaults or {}
771+
assert columns, "Tables must have at least one column"
771772
assert all(
772773
n in columns for n in not_null
773774
), "not_null set {} includes items not in columns {}".format(

tests/test_create.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,3 +1149,9 @@ def test_create_if_not_exists(fresh_db):
11491149
fresh_db["t"].create({"id": int})
11501150
# This should not
11511151
fresh_db["t"].create({"id": int}, if_not_exists=True)
1152+
1153+
1154+
def test_create_if_no_columns(fresh_db):
1155+
with pytest.raises(AssertionError) as error:
1156+
fresh_db["t"].create({})
1157+
assert error.value.args[0] == "Tables must have at least one column"

0 commit comments

Comments
 (0)