SQLProvider
SQLProvider copied to clipboard
sqlite - ``Create(...)`` function is incorrect
Create(...) function is missing NOT NULL columns - which does indeed result in a
Error: SQLite Error 19: 'NOT NULL constraint failed: kanji_service_attributes.ServiceName'.
during runtime.
Schema:
create table if not exists kanji (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Text TEXT NOT NULL,
CreatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
);
create table if not exists kanji_service_attributes (
ServiceName TEXT NOT NULL,
State INTEGER NOT NULL,
KanjiId INTEGER NOT NULL,
FOREIGN KEY (KanjiId) REFERENCES kanji(Id),
PRIMARY KEY (ServiceName, State)
);
Create(...) members:
ctx.Main.Kanji.``Create(Text)`` // 👍
ctx.Main.KanjiServiceAttributes.``Create(KanjiId)`` // 😱
Intentionally brief issue for lack of time but I can create a full repro for ease of debugging later. Would appreciate if someone could give me a sanity check before I create the full repro to make sure it's not just me forgetting how Sqlite works.
Yes it probably expects the primary key to be auto-inserted.
The correct way would be let itm = ctx.Main.KanjiServiceAttributes.``Create(KanjiId, ServiceName, State)``
As a work-around should you can do itm.ServiceName <- manually, but that's not optimal.