Skip to content

[Bug]: Scan fails for album spread across multiple folders (error="FOREIGN KEY constraint failed") #4002

@FriesischScott

Description

@FriesischScott

I confirm that:

  • I have searched the existing open AND closed issues to see if an issue already exists for the bug I've encountered
  • I'm using the latest version (your issue may have been fixed already)

Version

0.55.2

Current Behavior

I had the scan error with the message error="FOREIGN KEY constraint failed" for multiple albums. When I investigated it turned out what the albums had in common was that they had multiple discs and the tracks were in different folders for each disc but had the same album tag.

Once I moved the files into a single folder the scan completed without errors. I've attached the relevant log for one of the albums.

Expected Behavior

it should correctly scan the album from all CD subfolders.

Steps To Reproduce

Split an album with multiple discs into one subfolder per disc.

Environment

- OS:
- Browser:
- Client:

How Navidrome is installed?

Docker

Configuration

"HostConfig": {
            "Binds": [
                "/mnt/user/appdata/navidrome:/data:rw",
                "/mnt/user/Musik/:/music:rw"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {
                    "max-file": "1",
                    "max-size": "50m"
                }
            },
            "NetworkMode": "swag",
            "PortBindings": {
                "4533/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "4533"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "ConsoleSize": [
                0,
                0
            ],
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "private",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": [],
            "BlkioDeviceWriteBps": [],
            "BlkioDeviceReadIOps": [],
            "BlkioDeviceWriteIOps": [],
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": null,
            "PidsLimit": 2048,
            "Ulimits": [],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware",
                "/sys/devices/virtual/powercap"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": null,
            "Name": "btrfs"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/mnt/user/appdata/navidrome",
                "Destination": "/data",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/mnt/user/Musik",
                "Destination": "/music",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "d11ffcad33c8",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "4533/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "HOST_OS=Unraid",
                "ND_LASTFM_ENABLED=true",
                "ND_SPOTIFY_SECRET=*******************************",
                "ND_LASTFM_APIKEY=*******************************",
                "ND_LASTFM_SECRET=*******************************",
                "ND_SPOTIFY_ID=*******************************",
                "ND_PREFERSORTTAGS=true",
                "ND_BASEURL=",
                "ND_IMAGECACHESIZE=200MB",
                "TZ=Europe/Berlin",
                "HOST_HOSTNAME=Abaskun",
                "HOST_CONTAINERNAME=navidrome",
                "ND_SESSIONTIMEOUT=24h",
                "ND_SCANNER_SCHEDULE=0 * * * *",
                "ND_LOGLEVEL=debug",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ND_MUSICFOLDER=/music",
                "ND_DATAFOLDER=/data",
                "ND_CONFIGFILE=/data/navidrome.toml",
                "ND_PORT=4533",
                "GODEBUG=asyncpreemptoff=1"
            ],

Relevant log output

time="2025-04-25T11:20:28Z" level=error msg="SQL: `INSERT INTO album_artists (album_id,artist_id,role,sub_role) VALUES ({:p0},{:p1},{:p2},{:p3}),({:p4},{:p5},{:p6},{:p7}),({:p8},{:p9},{:p10},{:p11}),({:p12},{:p13},{:p14},{:p15}),({:p16},{:p17},{:p18},{:p19}),({:p20},{:p21},{:p22},{:p23}),({:p24},{:p25},{:p26},{:p27}),({:p28},{:p29},{:p30},{:p31}),({:p32},{:p33},{:p34},{:p35}) on conflict (artist_id, album_id, role, sub_role) do nothing`" args="map[p0:1mjoRy0wW00gCBHhepW7au p1:1uGq3V6LHwfH1yY25OCmIB p10:composer p11: p12:1mjoRy0wW00gCBHhepW7au p13:2A8QorY68sY42DoMe6ajrb p14:composer p15: p16:1mjoRy0wW00gCBHhepW7au p17:04YilwoWaYbZ3jA4Q6Cbjq p18:composer p19: p2:composer p20:1mjoRy0wW00gCBHhepW7au p21:1VQqB8NCdsYnq3g9d0YG9P p22:composer p23: p24:1mjoRy0wW00gCBHhepW7au p25:4vibw5gmapT2QV0eiRfVHA p26:composer p27: p28:1mjoRy0wW00gCBHhepW7au p29:4DwapAQ6KAeAbaSxFQWtDh p3: p30:albumartist p31: p32:1mjoRy0wW00gCBHhepW7au p33:4DwapAQ6KAeAbaSxFQWtDh p34:artist p35: p4:1mjoRy0wW00gCBHhepW7au p5:0w7zyCe0MwbcD9mPOk5VcR p6:composer p7: p8:1mjoRy0wW00gCBHhepW7au p9:23hUPN5RyQkVqd8K1o1TwD]" elapsedTime="335.075µs" error="FOREIGN KEY constraint failed" rowsAffected=0
time="2025-04-25T11:20:28Z" level=debug msg="Scanner: refreshing album" album_id=1mjoRy0wW00gCBHhepW7au elapsed=28.2ms error="FOREIGN KEY constraint failed" name="The Human Equation" songCount=31
time="2025-04-25T11:20:28Z" level=info msg="Scanner: Pipeline wall time: 1.39893501s\n  load albums from db (0): 1168 items, total 1.395566232s (1.194834ms/item), work 210.722115ms (180.412µs/item)\n  count tasks (0)        : 1168 items, total 1.395411578s (1.194701ms/item), work 252.6µs (216ns/item)\n  filter unmodified (0)  : 231 items, total 1.39541286s (6.040748ms/item), work 894.196524ms (3.87098ms/item)\n  filter unmodified (1)  : 241 items, total 1.39541367s (5.790098ms/item), work 899.257625ms (3.731359ms/item)\n  filter unmodified (2)  : 242 items, total 1.398758683s (5.779994ms/item), work 901.832569ms (3.72658ms/item)\n  filter unmodified (3)  : 229 items, total 1.39541167s (6.0935ms/item), work 927.069624ms (4.048338ms/item)\n  filter unmodified (4)  : 225 items, total 1.398083705s (6.213705ms/item), work 898.686256ms (3.994161ms/item)\n  refresh albums (0)     : 1159 items, total 1.398923153s (1.207008ms/item), work 536.029392ms (462.493µs/item)" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:20:28Z" level=error msg="Scanner: Error processing libraries in phase 3" elapsed=1.4s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:20:28Z" level=error msg="Scanner: Finished with error" duration=6.17s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:20:28Z" level=error msg="Error scanning" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed" requestId=d11ffcad33c8/4F51G1Bwf5-000006
time="2025-04-25T11:25:40Z" level=error msg="SQL: `INSERT INTO album_artists (album_id,artist_id,role,sub_role) VALUES ({:p0},{:p1},{:p2},{:p3}),({:p4},{:p5},{:p6},{:p7}),({:p8},{:p9},{:p10},{:p11}),({:p12},{:p13},{:p14},{:p15}),({:p16},{:p17},{:p18},{:p19}),({:p20},{:p21},{:p22},{:p23}),({:p24},{:p25},{:p26},{:p27}),({:p28},{:p29},{:p30},{:p31}),({:p32},{:p33},{:p34},{:p35}) on conflict (artist_id, album_id, role, sub_role) do nothing`" args="map[p0:1mjoRy0wW00gCBHhepW7au p1:4DwapAQ6KAeAbaSxFQWtDh p10:composer p11: p12:1mjoRy0wW00gCBHhepW7au p13:0w7zyCe0MwbcD9mPOk5VcR p14:composer p15: p16:1mjoRy0wW00gCBHhepW7au p17:23hUPN5RyQkVqd8K1o1TwD p18:composer p19: p2:albumartist p20:1mjoRy0wW00gCBHhepW7au p21:2A8QorY68sY42DoMe6ajrb p22:composer p23: p24:1mjoRy0wW00gCBHhepW7au p25:04YilwoWaYbZ3jA4Q6Cbjq p26:composer p27: p28:1mjoRy0wW00gCBHhepW7au p29:1VQqB8NCdsYnq3g9d0YG9P p3: p30:composer p31: p32:1mjoRy0wW00gCBHhepW7au p33:4vibw5gmapT2QV0eiRfVHA p34:composer p35: p4:1mjoRy0wW00gCBHhepW7au p5:4DwapAQ6KAeAbaSxFQWtDh p6:artist p7: p8:1mjoRy0wW00gCBHhepW7au p9:1uGq3V6LHwfH1yY25OCmIB]" elapsedTime="450.602µs" error="FOREIGN KEY constraint failed" rowsAffected=0
time="2025-04-25T11:25:40Z" level=debug msg="Scanner: refreshing album" album_id=1mjoRy0wW00gCBHhepW7au elapsed=75.7ms error="FOREIGN KEY constraint failed" name="The Human Equation" songCount=31
time="2025-04-25T11:25:40Z" level=info msg="Scanner: Pipeline wall time: 1.336129198s\n  load albums from db (0): 1168 items, total 1.32926651s (1.13807ms/item), work 198.092979ms (169.6µs/item)\n  count tasks (0)        : 1168 items, total 1.329328237s (1.138123ms/item), work 243.045µs (208ns/item)\n  filter unmodified (0)  : 230 items, total 1.329328033s (5.779687ms/item), work 923.591651ms (4.015615ms/item)\n  filter unmodified (1)  : 239 items, total 1.333272475s (5.578545ms/item), work 886.473539ms (3.709094ms/item)\n  filter unmodified (2)  : 232 items, total 1.336097751s (5.759042ms/item), work 891.313487ms (3.841868ms/item)\n  filter unmodified (3)  : 234 items, total 1.333886367s (5.700369ms/item), work 887.559975ms (3.792991ms/item)\n  filter unmodified (4)  : 233 items, total 1.329446466s (5.705778ms/item), work 880.7957ms (3.780239ms/item)\n  refresh albums (0)     : 1158 items, total 1.336109779s (1.153808ms/item), work 479.24323ms (413.854µs/item)" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:25:40Z" level=error msg="Scanner: Error processing libraries in phase 3" elapsed=1.34s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:25:40Z" level=error msg="Scanner: Finished with error" duration=6.12s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:25:40Z" level=error msg="Watcher: Error scanning" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:26:18Z" level=error msg="SQL: `INSERT INTO album_artists (album_id,artist_id,role,sub_role) VALUES ({:p0},{:p1},{:p2},{:p3}),({:p4},{:p5},{:p6},{:p7}),({:p8},{:p9},{:p10},{:p11}),({:p12},{:p13},{:p14},{:p15}),({:p16},{:p17},{:p18},{:p19}),({:p20},{:p21},{:p22},{:p23}),({:p24},{:p25},{:p26},{:p27}),({:p28},{:p29},{:p30},{:p31}),({:p32},{:p33},{:p34},{:p35}) on conflict (artist_id, album_id, role, sub_role) do nothing`" args="map[p0:1mjoRy0wW00gCBHhepW7au p1:4DwapAQ6KAeAbaSxFQWtDh p10:composer p11: p12:1mjoRy0wW00gCBHhepW7au p13:0w7zyCe0MwbcD9mPOk5VcR p14:composer p15: p16:1mjoRy0wW00gCBHhepW7au p17:23hUPN5RyQkVqd8K1o1TwD p18:composer p19: p2:albumartist p20:1mjoRy0wW00gCBHhepW7au p21:2A8QorY68sY42DoMe6ajrb p22:composer p23: p24:1mjoRy0wW00gCBHhepW7au p25:04YilwoWaYbZ3jA4Q6Cbjq p26:composer p27: p28:1mjoRy0wW00gCBHhepW7au p29:1VQqB8NCdsYnq3g9d0YG9P p3: p30:composer p31: p32:1mjoRy0wW00gCBHhepW7au p33:4vibw5gmapT2QV0eiRfVHA p34:composer p35: p4:1mjoRy0wW00gCBHhepW7au p5:4DwapAQ6KAeAbaSxFQWtDh p6:artist p7: p8:1mjoRy0wW00gCBHhepW7au p9:1uGq3V6LHwfH1yY25OCmIB]" elapsedTime="395.662µs" error="FOREIGN KEY constraint failed" rowsAffected=0
time="2025-04-25T11:26:18Z" level=debug msg="Scanner: refreshing album" album_id=1mjoRy0wW00gCBHhepW7au elapsed=85.1ms error="FOREIGN KEY constraint failed" name="The Human Equation" songCount=31
time="2025-04-25T11:26:18Z" level=info msg="Scanner: Pipeline wall time: 1.327218822s\n  load albums from db (0): 1168 items, total 1.31929703s (1.129535ms/item), work 195.80087ms (167.637µs/item)\n  count tasks (0)        : 1168 items, total 1.319331399s (1.129564ms/item), work 338.491µs (289ns/item)\n  filter unmodified (0)  : 236 items, total 1.319332986s (5.590394ms/item), work 871.964322ms (3.694764ms/item)\n  filter unmodified (1)  : 234 items, total 1.327199844s (5.671794ms/item), work 898.383538ms (3.839245ms/item)\n  filter unmodified (2)  : 235 items, total 1.323893409s (5.633588ms/item), work 859.305503ms (3.656619ms/item)\n  filter unmodified (3)  : 235 items, total 1.319359364s (5.614295ms/item), work 862.979437ms (3.672252ms/item)\n  filter unmodified (4)  : 228 items, total 1.323741698s (5.805884ms/item), work 867.258569ms (3.803765ms/item)\n  refresh albums (0)     : 1158 items, total 1.327203745s (1.146117ms/item), work 490.587659ms (423.65µs/item)" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:26:18Z" level=error msg="Scanner: Error processing libraries in phase 3" elapsed=1.33s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:26:18Z" level=error msg="Scanner: Finished with error" duration=6.11s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:26:18Z" level=error msg="Error scanning" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed" requestId=d11ffcad33c8/4F51G1Bwf5-000022
time="2025-04-25T11:27:13Z" level=error msg="SQL: `INSERT INTO album_artists (album_id,artist_id,role,sub_role) VALUES ({:p0},{:p1},{:p2},{:p3}),({:p4},{:p5},{:p6},{:p7}),({:p8},{:p9},{:p10},{:p11}),({:p12},{:p13},{:p14},{:p15}),({:p16},{:p17},{:p18},{:p19}),({:p20},{:p21},{:p22},{:p23}),({:p24},{:p25},{:p26},{:p27}),({:p28},{:p29},{:p30},{:p31}),({:p32},{:p33},{:p34},{:p35}) on conflict (artist_id, album_id, role, sub_role) do nothing`" args="map[p0:1mjoRy0wW00gCBHhepW7au p1:4DwapAQ6KAeAbaSxFQWtDh p10:composer p11: p12:1mjoRy0wW00gCBHhepW7au p13:23hUPN5RyQkVqd8K1o1TwD p14:composer p15: p16:1mjoRy0wW00gCBHhepW7au p17:2A8QorY68sY42DoMe6ajrb p18:composer p19: p2:artist p20:1mjoRy0wW00gCBHhepW7au p21:04YilwoWaYbZ3jA4Q6Cbjq p22:composer p23: p24:1mjoRy0wW00gCBHhepW7au p25:1VQqB8NCdsYnq3g9d0YG9P p26:composer p27: p28:1mjoRy0wW00gCBHhepW7au p29:4vibw5gmapT2QV0eiRfVHA p3: p30:composer p31: p32:1mjoRy0wW00gCBHhepW7au p33:4DwapAQ6KAeAbaSxFQWtDh p34:albumartist p35: p4:1mjoRy0wW00gCBHhepW7au p5:1uGq3V6LHwfH1yY25OCmIB p6:composer p7: p8:1mjoRy0wW00gCBHhepW7au p9:0w7zyCe0MwbcD9mPOk5VcR]" elapsedTime="463.97µs" error="FOREIGN KEY constraint failed" rowsAffected=0
time="2025-04-25T11:27:13Z" level=debug msg="Scanner: refreshing album" album_id=1mjoRy0wW00gCBHhepW7au elapsed=15.8ms error="FOREIGN KEY constraint failed" name="The Human Equation" songCount=31
time="2025-04-25T11:27:13Z" level=info msg="Scanner: Pipeline wall time: 1.395961245s\n  load albums from db (0): 1168 items, total 1.392204625s (1.191956ms/item), work 199.78118ms (171.045µs/item)\n  count tasks (0)        : 1168 items, total 1.392214012s (1.191964ms/item), work 282.402µs (241ns/item)\n  filter unmodified (0)  : 234 items, total 1.392214973s (5.949636ms/item), work 896.182541ms (3.829839ms/item)\n  filter unmodified (1)  : 226 items, total 1.392215909s (6.160247ms/item), work 903.083796ms (3.995946ms/item)\n  filter unmodified (2)  : 234 items, total 1.392194814s (5.94955ms/item), work 896.800026ms (3.832478ms/item)\n  filter unmodified (3)  : 239 items, total 1.395061481s (5.837077ms/item), work 908.954829ms (3.803158ms/item)\n  filter unmodified (4)  : 235 items, total 1.39558252s (5.938649ms/item), work 920.900916ms (3.918727ms/item)\n  refresh albums (0)     : 1159 items, total 1.395606975s (1.204147ms/item), work 532.144782ms (459.141µs/item)" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:27:13Z" level=error msg="Scanner: Error processing libraries in phase 3" elapsed=1.4s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:27:13Z" level=error msg="Scanner: Finished with error" duration=6.23s error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:27:13Z" level=error msg="Watcher: Error scanning" error="refreshing album 1mjoRy0wW00gCBHhepW7au: FOREIGN KEY constraint failed"
time="2025-04-25T11:38:51Z" level=debug msg="Found album artwork" artID=al-1mjoRy0wW00gCBHhepW7au_0 elapsed="494.939µs" path="/music/A/Ayreon/2004 The Human Equation/cover.jpg" requestId=d11ffcad33c8/4F51G1Bwf5-000209 source=fromCoverArtPriority.fromExternalFile.func4
time="2025-04-25T11:38:51Z" level=debug msg="HTTP: GET http://navidrome.friesischscott.de/rest/getCoverArt?u=jasper&t=[REDACTED]&s=[REDACTED]&f=json&v=1.8.0&c=NavidromeUI&id=al-1mjoRy0wW00gCBHhepW7au&_=2025-04-25T11%3A28%3A42.101Z&size=300&square=true" elapsedTime=276.8ms httpStatus=200 remoteAddr=89.244.196.193 requestId=d11ffcad33c8/4F51G1Bwf5-000209 responseSize=200872 userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0"
time="2025-04-25T12:17:50Z" level=debug msg="HTTP: GET http://navidrome.friesischscott.de/rest/getCoverArt.view?id=al-1mjoRy0wW00gCBHhepW7au_680b71ea&u=jasper&t=[REDACTED]&s=[REDACTED]&v=1.13.0&c=Symfonium&f=json" elapsedTime=3.4ms httpStatus=200 remoteAddr=89.244.196.193 requestId=d11ffcad33c8/4F51G1Bwf5-000687 responseSize=242778 userAgent="Symfonium/12.3.0 (Linux;Android 15)"

Anything else?

No response

Code of Conduct

  • I agree to follow Navidrome's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtriageNew bug reports that need to be evaluated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions