Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite - Create(...) function is incorrect #841

Open
johnW-ret opened this issue Feb 12, 2025 · 1 comment
Open

sqlite - Create(...) function is incorrect #841

johnW-ret opened this issue Feb 12, 2025 · 1 comment

Comments

@johnW-ret
Copy link

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.

@Thorium
Copy link
Member

Thorium commented Feb 12, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants