skip to main content

Synchronizing digiKam 2.9.0 database and image metadata

I'm pretty sure the problems described on this page have been partially fixed in digiKam 3.5 and completely fixed in digiKam 4.2. See Bug 268688 - Write metadata to all images does not remove obsolete tags for details. I'll leave this page up in case the information helps someone who needs to deal with residual "lack of synchronization" problems.

Written October 2012.

  1. The problem: After rearranging tags, the image metadata and database are no longer synchronized. If you have digiKam set up to write metadata to the images instead of just to the database, when you rearrange tags on the tag tree, or even just rename a tag, what usually happens is that the image metadata and the digiKam database get unsynchronized. Rearranging the tag tree has left old, outdated tags in the image metadata. The first set of pictures below illustrate the usual way images and the database get out of synchronization. See digiKam bug 268688 to keep track of when/whether this bug has been fixed.
  2. The solution painfully tedious workaround: "Filter/Select all tags" before rearranging tags. The images and database can be resynchronized, but "how" is not intuitively obvious. The second set of pictures below show step-by step-how to get the images and database back into synchronization. Unfortunately, you might need to delete your database and create a new database several times before you succeed in getting rid of all the old tags. Even more unfortunately, you'll probably need to do it all again the next time you rearrange the tag tree.

Note 1: Many thanks to More digiKam Tagging Quirks for providing the clue as to how to synchronize the images and database. I don't understand what the post means about "Toggle Auto/Parents" in the left-side tags panel; the post was written in 2009, so perhaps the digiKam interface has changed.

Note 2: The steps on this page do not work if you are writing to XMP sidecar files instead of to the image files.

Note 3: You probably want to test these steps on a few images or a test database, before deploying on your real database. And backup your database first, just in case. In other words, follow these instructions at your own risk.

Note 4: The good news is this issue seems to have been fixed in digiKam 3.4.

The problem: After rearranging tags, the image metadata and database are no longer synchronized

  1. Metadata settings:

    The metadata settings tell digiKam to write metadata to the images. As shown below, it is possible to synchronize the database and the image metadata if you allow digiKam to write to the images.

  2. New database with untagged images. The tags have been created, but no tags have been assigned to the images:

    Exiftool shows that the database is synchronized with the images (no tags have been assigned yet).

  3. Tags have been assigned to both images:

    Tags have been assigned to both images. The tags haven't been rearranged. The database and image metadata are still synchronized.

  4. A new tag, "newtopleveltag", has been created; "sometag" and "another tag" have been placed under "newtopleveltag". Now the database and the image metadata are no longer synchronized:

    The tag tree has been rearranged and now the database and image metadata are no longer synchronized. The image metadata has the outdated tags AND the new tags, eg, the outdated tag "anothertag/subtag2" and the new tag "newtopleveltag/anothertag/subtag2".

  5. The "country" and "stateprovince" tags have been rearranged to be top-level tags, and the "location" tag tree has been removed, making the database and image metadata even more out of synchronization with each other:

    In the database, the "country" and "stateprovince" tags have been made top-level tags, and the old "location" tag has been removed from the database. Now the database and the image metadata are even more out of synchronization: the "country" and "stateprovince" tag trees are in the image metadata twice, once in their new locations as top-level tags, and once again in their old location under the outdated "location" top-level tag.

    As an aside, see the new tag "People" in the left Captions/Tags side pane? I didn't create that tag. digiKam put it there all by itself. It's not assigned to any images, so deleting won't cause any problems.

The solution painfully tedious workaround

  1. Select all the images and reread the image metadata — "Image/Reread Metadata from selected images":

    The first step is to resynchronize the database and the image metadata by:

    (i)selecting all the images;
    (ii)writing all the database information out to the images; and
    (iii)rereading all the image metadata.

    Theoretically, this step will pull in all the tags you've removed from your database. So now the database and the images are (or should be) synchronized, and the outdated tags can be removed.

    Unfortunately, sometimes writing and then rereading all the image metadata fails to pull in all the unwanted tags that are in still the image but no longer in the database. In the present case, the unwanted "location" tag tree was pulled in. But the unwanted "sometag" and "anothertag" trees were not pulled in. It will take an extra step to get rid of any tags that aren't pulled in by rereading the image metadata.

    The next steps below will get rid of the unwanted tags (the ones that were successfully pulled in by rereading the image metadata) without letting the database and the image metadata get out of synchronization.

  2. This is the critical step to keeping the image metadata synchronized with the database. Before rearranging (and also before renaming) any tags, first go to the right-side Tags Filter panel and do "Select/Select all tags":

    This step is not intuitive but it's necessary if you want to keep your image metadata synchronized with the database.

  3. Go to the right-side "Captions/Tags" panel (all the tags in the "Tags Filter" panel are still selected). Select all the images in the center panel:

    All the images have been selected. All the tags in the "Tags Filter" panel are still selected. Now it is possible (see the next step below) to unassign all the outdated tags under the "location" tag tree, and then delete the unwanted "location" tag tree from the database, while keeping the image metadata and the database synchronized.

  4. Deselect all the unwanted "location" tags (all the tags in the "Tags Filter" panel are still selected), apply, write to the images in the usual way. This time the outdated "location" tags will be gone from the database AND from the image metadata:

    After deselecting all the unwanted "location" tags and applying/writing to the images (sometimes "applying" by itself writes to the image, but not all the time), the "location" tag tree is gone from all the image metadata.

  5. Now delete the "location" tag tree. The database tag tree now looks like it's supposed to look. But unfortunately the image metadata still isn't completely synchronized with the database because rereading the image metadata didn't pull in all of the outdated tags that were written to the images:

    The database tag tree looks like it's supposed to look. But unfortunately the image metadata isn't completely synchronized with the database because rereading the image metadata didn't pull in all of the tags written to the images. The old "sometag" and "anothertag" trees are still in the image metadata. The next step below will get rid of these remaining outdated tag trees.

  6. Delete the digiKam database (or move it someplace out of the way and delete it later) and create a new database:

    Creating a new database allowed digiKam to pull in all the tags in the image metadata. Now the remaining outdated tags can be deleted.

  7. As before, go to the right panel "Tags Filter" and "Select/Select all tags":

    Again, this is the critical step. If you don't select all the tags using the Tags Filter before rearranging the tag tree, the database and image metadata won't be synchronized.

  8. Switch to the right side "Captions/Tags" panel (all the tags are still selected in the Tags Filter panel). In the center panel, select all the images:

    Switch to the "Captions/Tags" panel and select all the images in the center panel. All the tags are still selected in the Tags Filter panel.

  9. Unassign all the tags in the outdated "sometag" and "anothertag" trees (all the tags are still selected in the Tags Filter panel). Apply/write to the images as usual:

    All the unwanted tags have been unassigned and the database is synchronized with the image metadata.

  10. Now the unwanted tags can be safely deleted from the database, and the database will still be synchronized with the image metadata:

    Finally, the database and the image metadata are completely synchronized. To keep them synchronized, make sure that all the tags are selected in the "Tags Filter" before rearranging or renaming any tags.

Unfortunately, even when taking the extra step of selecting all the tags in the "Tags Filter", sometimes digiKam still doesn't manage to remove the outdated tags before it writes the new tags to the image metadata. The solution is "wash, rinse, repeat". That is, select all the images, write the metadata out to the images. Then delete (or stash) the database, create a new database, and then proceed as above to delete all the remaining outdated tags.

I put this information up for anyone who really wants to resynchronize their image metadata with the digiKam database. However, the above procedure is a workaround and the process is fiddly, tedious, and slow. So if you are doing a lot of tag tree rearranging, you might want to just wait until digiKam bug 268688 is fixed, or until you are completely satisfied with the tag tree and don't anticipate rearranging it again.

Components information:

digiKam version 2.9.0
Exiv2 can write to Jp2: Yes
Exiv2 can write to Jpeg: Yes
Exiv2 can write to Pgf: Yes
Exiv2 can write to Png: Yes
Exiv2 can write to Tiff: Yes
Exiv2 supports XMP metadata: Yes
LibCImg: 130
LibClapack: internal library
LibExiv2: 0.23
LibJPEG: 62
LibJasper: 1.900.1
LibKDE: 4.9.2 "release 511"
LibKExiv2: 2.3.0
LibKGeoMap: 2.0.0
LibKdcraw: 2.1.0
LibLCMS: 119
LibLensFun: external shared library
LibLqr: internal library
LibPGF: 6.12.27 - internal library
LibPNG: 1.4.11
LibQt: 4.8.3
LibRaw: 0.15.0-Alpha4
LibTIFF: LIBTIFF, Version 4.0.2 Copyright (c) 1988-1996 Sam Leffler Copyright (c) 1991-1996 Silicon Graphics, Inc.
Marble Widget: 0.14.1 (stable release)
Parallelized PGF codec: No
Parallelized demosaicing: Yes
Database backend: QSQLITE
LibGphoto2: 2.4.14
LibKface: 2.0.0
LibKipi: 1.6.0
LibOpenCV: 2.4.1
Libface: 0.2