darktable tags have gotten corrupted

I have a collection of 9461 images in my darktable database. I have every one of these images tagged with at least two tags, identifying location and subject. Somehow the tags have suddenly gotten all messed up. All of my tags still exist, but about half of my images now have the wrong tags applied, and 2463 of them now have no tags at all.

Can anyone tell me what might have happened, and more importantly, is there a way to fix this without having to go through my entire collection retagging every image individually?

I can’t help you with the ‘what happened’ part, but the restore part may be relatively easy: tags are saved in the database, and database files are backed up regularly (if you didn’t change that option). First thing I’d do would be to copy all database backups out from darktable’s config folder to avoid losing any of them while you analyze the solution. Then, you can start darktable with a new config folder, putting there the database files (library.db and data.db), going back one backup at a time to check were corruption happened. If you’re lucky, it happened recently and one of the backups will be OK. You can then start using them as your new database in the normal folder.

Caveats:

  • you’ll lose any edit since that backup
  • if you have both ‘xmp saving’ and ‘check for xmp changes at startup’ enabled, you should be careful with overriding the backup database with the xmp version, as the later could have the wrong tags version (you may go the extra mile and check that beforehand)
2 Likes

Thanks! The most recent backup fixed it, so I just need to re-enter the last week’s worth of photos. That’s a relief!

3 Likes

more importantly check the disk that database is on. this may be hardware issue and could be the start of a drive failure. What type, make and model drive are you are you using?

The tags should also be in the XMP files. Normally, if an image is already in the database, the XMP is not read, but:

  • you can remove and re-import the images; that will populate the DB with the data from the XMP;
  • alternatively, at least for now, you can enable the setting that @guille2306 has mentioned (it causes slow start-up, if you have many images, so you should probably turn it off afterwards). Darktable will then update the DB based on the XMP, no need to remove/re-import the photos:

    Once an image has been imported into darktable, the database entries take precedence over the XMP file. Subsequent changes to the XMP file by any other software are not visible to darktable – such changes will be overwritten the next time darktable synchronizes the file. On request, darktable can be configured to search for updated XMP files at startup, offering a choice to update the database or overwrite the XMP file where changes are identified. This configuration can be changed in preferences > storage > xmp.
    (darktable 4.6 user manual - sidecar files)

1 Like