Bug 497151 - "QMYSQL: Unable to execute query" "Unknown column 'context' in 'FaceMatrices'" "1054" 2
Summary: "QMYSQL: Unable to execute query" "Unknown column 'context' in 'FaceMatrices'...
Status: RESOLVED NOT A BUG
Alias: None
Product: digikam
Classification: Applications
Component: Database-Faces (show other bugs)
Version: 8.5.0
Platform: Appimage Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-07 07:34 UTC by Petr Schonmann
Modified: 2025-02-02 15:44 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 8.6.0
Sentry Crash Report:


Attachments
debug log (53.47 KB, text/plain)
2024-12-07 07:34 UTC, Petr Schonmann
Details
mysql schema (32.22 KB, application/sql)
2024-12-07 07:35 UTC, Petr Schonmann
Details
debug_log_20241207_224452.txt (53.13 KB, text/plain)
2024-12-07 21:55 UTC, Petr Schonmann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Schonmann 2024-12-07 07:34:44 UTC
Created attachment 176408 [details]
debug log

SUMMARY
Ive run updated app image to latest stable 8.5

STEPS TO REPRODUCE
1. Just start
2. its in console
3. log included with myqsl schema without data

OBSERVED RESULT
Seems nothing is broken and app is working, but probably some mysql tables are not renamed

EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: 
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Comment 1 Petr Schonmann 2024-12-07 07:35:25 UTC
Created attachment 176409 [details]
mysql schema
Comment 2 Maik Qualmann 2024-12-07 07:46:41 UTC
You probably used test version when we had a bug in the update function for the face database.
The best way is to set the version number in the FaceSettings table to a small version, use 2. Then everything will be rebuilt.

Maik
Comment 3 Petr Schonmann 2024-12-07 10:26:16 UTC
Tried 
mysql> select * from FaceSettings;
+-----------------------+-------+
| keyword               | value |
+-----------------------+-------+
| DBFaceVersion         | 4     |
| DBFaceVersionRequired | 4     |
+-----------------------+-------+
2 rows in set (0.00 sec)

mysql> update FaceSettings value=2;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=2' at line 1
mysql> update FaceSettings set value=2;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0

mysql> select * from FaceSettings;
+-----------------------+-------+
| keyword               | value |
+-----------------------+-------+
| DBFaceVersion         | 2     |
| DBFaceVersionRequired | 2     |
+-----------------------+-------+

but this give me another error :) and nothing is reindexed

2024-12-07 11:25:24.150794 Digikam::FaceDb::setting: FaceDB SelectFaceSetting val ret = 0
2024-12-07 11:25:24.152026 Digikam::FaceDb::setting: FaceDB SelectFaceSetting val ret = 0
2024-12-07 11:25:24.152078 Digikam::FaceDbSchemaUpdater::startUpdates: Face database: have a structure version  "2"
2024-12-07 11:25:24.245016 Digikam::BdEngineBackendPrivate::debugOutputFailedQuery: Failure executing query:
2024-12-07 11:25:24.245231  "" 
2024-12-07 11:25:24.245266 Error messages: "QMYSQL: Unable to execute query" "BLOB/TEXT column 'removeHash' used in key specification without a key length" "1170" 2 
2024-12-07 11:25:24.245302 Bound values:  QList()
2024-12-07 11:25:24.254798 Digikam::BdEngineBackend::execDBAction: Error while executing DBAction [ "IndexFaceDBFaceMatrices_removeHash_V5" ] Statement [ "CREATE INDEX idx_FaceMatricesHash \n                                        ON FaceMatrices(removeHash);\n                " ]
2024-12-07 11:25:24.255402 Digikam::FaceDbSchemaUpdater::updateV2ToV5: fail to create FaceMatrices index
2024-12-07 11:25:24.257156 Digikam::FacialRecognitionWrapper::Private::Private: Face database ready for use

Is it posible to send me db query to execute if previous was wrong ?
Comment 4 Maik Qualmann 2024-12-07 11:49:59 UTC
Ok, the best way is to delete all the tables in the face database. digiKam will recreate them. Then rebuild the training database in the maintenance tool. Delete the following tables:

Identities
IdentityAttributes
FaceSettings
FaceMatrices
KDTree

You may need to temporarily run SET FOREIGN_KEY_CHECKS=0; to delete the tables, then re-enable them with
SET FOREIGN_KEY_CHECKS=1;

Maik
Comment 5 Petr Schonmann 2024-12-07 21:54:35 UTC
Still is something wrong.
Ive drop tables from digikam database ( all tables are in digikam databases, not split ) config from digikamrc below

SET FOREIGN_KEY_CHECKS=0;
drop table Identities;
drop table IdentityAttributes;
drop table FaceSettings;
drop table FaceMatrices;
drop table KDTree;
SET FOREIGN_KEY_CHECKS=1;


digikamrc databases vvvv

Database Name=digikam
Database Name Face=digikam
Database Name Similarity=digikam
Database Name Thumbnails=digikam

Error

2024-12-07 22:45:04.925396 Digikam::FaceDb::setting: FaceDB SelectFaceSetting val ret = 0
2024-12-07 22:45:04.926853 Digikam::FaceDb::setting: FaceDB SelectFaceSetting val ret = 0
2024-12-07 22:45:04.926899 Digikam::FaceDbSchemaUpdater::startUpdates: Face database: have a structure version  ""
2024-12-07 22:45:04.926922 Digikam::FaceDbSchemaUpdater::startUpdates: DBFaceVersion not available! Giving up schema upgrading.
2024-12-07 22:45:04.926963 Digikam::FaceDbAccess::checkReadyForUse: Face database: cannot process schema initialization
2024-12-07 22:45:04.926985 Digikam::FacialRecognitionWrapper::Private::Private: Failed to initialize face database

full log in attachement debug_log_20241207_224452.txt

mysql not contain any record in tbl FaceSettings >> probably not properly recreated after mysql drop tables

mysql> select * from FaceSettings;
Empty set (0.00 sec)
Comment 6 Petr Schonmann 2024-12-07 21:55:03 UTC
Created attachment 176424 [details]
debug_log_20241207_224452.txt
Comment 7 Maik Qualmann 2024-12-08 07:01:07 UTC
I tested it here with my SQL database, deleted all face database tables. These are created without any problems.
The trigger is the "Identities" table, if this does not exist, everything is recreated. An "Identities" table is still found in your database. This is why an update is attempted incorrectly.

Maik
Comment 8 Petr Schonmann 2024-12-09 10:45:19 UTC
Ive deleted all tables with drop, the databases are created okay, but not with data.
---
root@db:~# while read -r line;do mysql -D digikam -e "select count(*) from $line";done < FACES_tables.list 
count(*)
0
count(*)
0
count(*)
0
count(*)
0
count(*)
0

Then i added setting into FaceSettings with this,

INSERT INTO `FaceSettings` (`keyword`, `value`) VALUES ('DBFaceVersion', '2');
INSERT INTO `FaceSettings` (`keyword`, `value`) VALUES ('DBFaceVersionRequired', '4');

it change the error message to the previous one
Comment 9 Maik Qualmann 2024-12-09 11:19:58 UTC
No, do not create a FaceSettings table manually. If digiKam does not find a "Identities" table, digiKam will create all tables again.

Maik
Comment 10 Petr Schonmann 2024-12-15 13:11:16 UTC
I drop only one table now, identities. No data(rows with settings) backfilled in empty table FaceSettings. But Identities table is created. Only one thing i see in procedures is

create_index_if_not_exists

Maybe problem can be im not using maria but percona 8.x
Comment 11 Maik Qualmann 2024-12-15 18:03:38 UTC
Git commit fa198d314991f8823980f757b03ad63142cd0ebd by Maik Qualmann.
Committed on 15/12/2024 at 18:02.
Pushed by mqualmann into branch 'master'.

create face table index only with check for MySQL

M  +3    -13   core/data/database/dbconfig.xml.cmake.in
M  +5    -8    core/libs/facesengine/facedb/facedbschemaupdater.cpp

https://invent.kde.org/graphics/digikam/-/commit/fa198d314991f8823980f757b03ad63142cd0ebd
Comment 12 Maik Qualmann 2024-12-15 18:07:58 UTC
Does an error message appear because of "create_index_if_not_exists"? That would be fatal, as this internal function is specifically for Oracle MySQL, as it does not support this function. We have been using the function for a long time and often when updating digiKam.
I didn't know percona until now, it seems to be based on MySQL.

Maik
Comment 13 Petr Schonmann 2024-12-19 22:00:11 UTC
Seems that problem or some restrictions in percona. Tried from scratch with percona and get same error with empty database.
Then i purged percona and installed latest maria. Error gone