Default to NOT NULL for table constraints
Ideally, we'd update all existing tables to add the new constraints, but sqlite doesn't offer an easy way to do so: https://www.sqlite.org/lang_altertable.html Since that migration really isn't worth the effort, we only set the constraint for new tables...
This commit is contained in:
parent
b06a38ce7e
commit
1603b15cfd
@ -161,7 +161,8 @@ class SqlTable(QObject):
|
|||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
constraints = constraints or {}
|
constraints = constraints or {}
|
||||||
column_defs = ['{} {}'.format(field, constraints.get(field, ''))
|
default = 'NOT NULL'
|
||||||
|
column_defs = ['{} {}'.format(field, constraints.get(field, default))
|
||||||
for field in fields]
|
for field in fields]
|
||||||
q = Query("CREATE TABLE IF NOT EXISTS {name} ({column_defs})"
|
q = Query("CREATE TABLE IF NOT EXISTS {name} ({column_defs})"
|
||||||
.format(name=name, column_defs=', '.join(column_defs)))
|
.format(name=name, column_defs=', '.join(column_defs)))
|
||||||
|
Loading…
Reference in New Issue
Block a user