My KV binding is not being set by my wrangler.toml file when deploying to my production environment

Hello Cloudflare Community! My KV binding is not being set by my wrangler.toml file when deploying to my production environment. It works fine on the staging worker, but when I deploy to the production worker the KV binding is wiped, so I have to add it manually using the dashboard after each deploy (which causes downtime). In my wrangler.toml file, I’m setting kv_namespaces in exactly the same way in [env.production] as I am in [env.staging], and also in the top section of the file (with no environment). I’ve searched through this community and can’t find any posts on this exact topic. Below is my full wrangler.toml, and a screenshot of the dashboard with the message recommending updating my wrangler.toml file to keep your local development environment in sync (which I have done). Thanks very much in advance for your help!
name = "renderer"
account_id = "16875cc7c5ec0ad968518988c731fcab"
workers_dev = false
compatibility_date = "2022-01-20"
main = "src/api/index.ts"

[vars]
ENVIRONMENT = "production"

[build]
command = "npm run build-worker"

kv_namespaces = [
{ binding = "FLOWS_KV", id = "00ca5df4edfa475e82a209d3de5e6d19", preview_id = "00ca5df4edfa475e82a209d3de5e6d19" }
]

[env.production]
vars = { ENVIRONMENT = "production" }
workers_dev = true
kv_namespaces = [
{ binding = "FLOWS_KV", id = "00ca5df4edfa475e82a209d3de5e6d19", preview_id = "00ca5df4edfa475e82a209d3de5e6d19" }
]

[env.staging]
vars = { ENVIRONMENT = "staging" }
kv_namespaces = [
{ binding = "FLOWS_KV", id = "00ca5df4edfa475e82a209d3de5e6d19", preview_id = "00ca5df4edfa475e82a209d3de5e6d19" }
]
name = "renderer"
account_id = "16875cc7c5ec0ad968518988c731fcab"
workers_dev = false
compatibility_date = "2022-01-20"
main = "src/api/index.ts"

[vars]
ENVIRONMENT = "production"

[build]
command = "npm run build-worker"

kv_namespaces = [
{ binding = "FLOWS_KV", id = "00ca5df4edfa475e82a209d3de5e6d19", preview_id = "00ca5df4edfa475e82a209d3de5e6d19" }
]

[env.production]
vars = { ENVIRONMENT = "production" }
workers_dev = true
kv_namespaces = [
{ binding = "FLOWS_KV", id = "00ca5df4edfa475e82a209d3de5e6d19", preview_id = "00ca5df4edfa475e82a209d3de5e6d19" }
]

[env.staging]
vars = { ENVIRONMENT = "staging" }
kv_namespaces = [
{ binding = "FLOWS_KV", id = "00ca5df4edfa475e82a209d3de5e6d19", preview_id = "00ca5df4edfa475e82a209d3de5e6d19" }
]
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jeremy Evans
Jeremy Evans2y ago
Thank you very much @sapkotamadan ! I'll try that on our next deploy.
Jeremy Evans
Jeremy Evans2y ago
Hi @sapkotamadan , thanks for the suggestion but unfortunately after deploying the wrangler.toml code you wrote above, the same issue is still there. On deploy to production, it wiped the KV binding and I had to add it in again, causing downtime. Have you any idea why this might be happening? Thanks!
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Jeremy Evans
Jeremy Evans2y ago
Thanks @sapkotamadan , I was aware of that, and was doing exactly that, but the production one was not binding (even though the development one was working). However, I tried removing the preview and then production worked! So thanks for your help. Cloudflare definitely need to update their docs to make it clear that KV bindings will break if you include a preview in your production settings.
Want results from more Discord servers?
Add your server