It’s very unexpected behavior for docker compose IMHO. When you say the volume is named “foo” it creates a volume named “directory_foo”. Same with all the container names.
You do have some control over that by setting a project name. So you could re-use your old volumes with the new directory name.
Or if you want to migrate from an old volume to a new one you can create a container with both volumes mounted and copy your data over by doing something like this:
<span style="color:#323232;">docker run -it --rm -v old_volume:/old:ro -v new_volume:/new ubuntu:latest
</span><span style="color:#323232;">$ apt update </span><span style="font-weight:bold;color:#a71d5d;">&& </span><span style="color:#323232;">apt install -y rsync
</span><span style="color:#323232;">$ rsync -rav --progress --delete /old/ /new/ </span><span style="font-style:italic;color:#969896;"># be *very* sure to have the order of these two correct!
</span><span style="color:#323232;">$ exit
</span>
For the most part applications won’t “delete and re-create” a data source if it finds one. The logic is “did I find a DB, if so then use it, else create a fresh one.”