CommandNotFound database foreign key constraint fail
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
command-not-found (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
```
$ lsb_release -rd
Description: Ubuntu 20.04.3 LTS
Release: 20.04
```
I have compiled sqlite3 with enabled foreign keys support - https:/
When I wanted to fetch latest `apt` changes, I got the following error:
$ sudo apt update
Hit:1 https:/
...
Traceback (most recent call last):
File "/usr/lib/
col.create(db)
File "/usr/lib/
raise e
File "/usr/lib/
self.
File "/usr/lib/
self.
File "/usr/lib/
self.
File "/usr/lib/
con.execute("""
sqlite3.
```
which is clearly an incorrect naming in the `create_table_sql` in `CommandNotFoun
but since sqlite3 does not enforce foreign keys, you can get away with all sorts of funky stuff:
```
sqlite> PRAGMA foreign_keys=OFF;
sqlite> CREATE TABLE tbl1(a, b NOT NULL, FOREIGN KEY (b) REFERENCES "nonexistent" (b));
sqlite>
sqlite> INSERT INTO tbl1 VALUES (1, 2); -- No problem!
```
The first patch attempted was therefore:
```
$ git diff
diff --git a/CommandNotFou
index d887c9d..a52be56 100755
--- a/CommandNotFou
+++ b/CommandNotFou
@@ -34,7 +34,7 @@ create_db_sql="""
- FOREIGN KEY ([pkgID]) REFERENCES "pkgs" ([pkgID])
+ FOREIGN KEY ([pkgID]) REFERENCES "packages" ([pkgID])
);
CREATE TABLE IF NOT EXISTS "packages"
(
```
which resulted in another error in `$ sudo apt update`:
```
Traceback (most recent call last):
File "/usr/lib/
col.create(db)
File "/usr/lib/
self.
File "/usr/lib/
self.
File "/usr/lib/
self.
File "/usr/lib/
con.
sqlite3.
```
which is understandable, since default as per sqlite docs for `FOREIGN KEY` is `NO ACTION`. Final patch is thus adding `ON UPDATE CASCADE ON UPDATE DELETE`:
```
$ git diff
diff --git a/CommandNotFou
index d887c9d..a52be56 100755
--- a/CommandNotFou
+++ b/CommandNotFou
@@ -34,7 +34,7 @@ create_db_sql="""
- FOREIGN KEY ([pkgID]) REFERENCES "pkgs" ([pkgID])
+ FOREIGN KEY ([pkgID]) REFERENCES "packages" ([pkgID]) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS "packages"
(
```
Now, as I would expect, `apt update` works as usual:
```
$ sudo apt update
...
Reading package lists... Done
Building dependency tree
Reading state information... Done
17 packages can be upgraded. Run 'apt list --upgradable' to see them.
```
Best regards,
Libor
$ sudo apt update
...
Reading package lists... Done
Building dependency tree
Reading state information... Done
17 packages can be upgraded. Run 'apt list --upgradable' to see them.
```
Best regards,
Libor
The attachment "db_create_ sql_bug. patch" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.
[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]