sqlite-mode-extras icon indicating copy to clipboard operation
sqlite-mode-extras copied to clipboard

Database error: "NOT NULL constraint failed"

Open sonn-gamm opened this issue 1 year ago • 4 comments

Hi! Amazing extras for sqlite-mode.

I get the following error when adding a new row with +:

funcall-interactively: Database error: "NOT NULL constraint failed: <table>.<col>"

I can add a new row by hand using the sqlite CLI program. Is your code expecting something specific I am not doing or is my schema acting up?

Thanks.

sonn-gamm avatar Aug 20 '24 16:08 sonn-gamm

Hey, hard to tell without more details. Can you share a sample db with the same or similar schema? Alternatively, if you set an edebug breakpoint on sqlite-mode-extras-add-row and step through the code, we can get an idea of what's going wrong.

xenodium avatar Aug 21 '24 13:08 xenodium

Apologies for the late reply!

Here the sqlite schema:

sqlite> .schema
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE locations (
id INTEGER PRIMARY KEY,
location TEXT NOT NULL
);
CREATE TABLE people (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
website TEXT UNIQUE,
email TEXT UNIQUE,
type TEXT NOT NULL,
location_id INTEGER,
contacted TEXT,
responded TEXT,
notes TEXT
,
FOREIGN KEY (location_id) REFERENCES locations(id)
);

Let me know what else I can do. I am trying to learn how to use edebug.

sonn-gamm avatar Sep 17 '24 16:09 sonn-gamm

sqlite-mode-extras-add-row currently depends on inserting a new row with default values ("INSERT INTO people DEFAULT VALUES;") and fails with no default columns.

You can still use sqlite-mode-extras-compose-and-execute as a workaround.

We could consider prompting users for all non-default values or maybe providing generic ones that can be overriden post insertion like defaults work now.

xenodium avatar Sep 26 '24 21:09 xenodium

All clear, and not a big deal. Indeed, I've been enjoying using sqlite-mode-extras-compose-and-execute meanwhile and will start use it also for inserting new rows. Thanks!

sonn-gamm avatar Sep 27 '24 08:09 sonn-gamm