Hi All, I am facing an issue using D1

Hi All, I am facing an issue using D1 locally. The issue is my worker cannot see any of the DB objects I have created. First, I setup my DB with some DDL: wrangler d1 execute appdb-dev --local --file=./1.sql Then I can query the DB: wrangler d1 execute appdb-dev --local --command="SELECT * FROM User" // works However, when I try to access my local d1 instance in the worker, it can't find any tables. It is obviously looking at some other local instance, but I can't find any way to list the local instances, or don't know the commands to understand whether I am looking at the right one. Any ideas? Wrangler.toml below: name = "app-services" compatibility_date = "2023-12-01" route = "api.myapp.app/*" compatibility_flags = ["nodejs_compat"] [vars] LOG_LEVEL="debug" TEST_MODE="TRUE" kv_namespaces = [ { binding = "MYAPP_TOKENS", preview_id = "###", id = "###" }, ] [[d1_databases]] binding = "DB" database_name = "appdb-dev" database_id = "###" preview_database_id = "appdb-dev" [env.dev] route = "dev-api.myapp.app/*"
3 Replies
harshil1712
harshil17125mo ago
Did you create the database from the same worker project from where you are trying to access it? When running locallly, a copy of the db is created inside a .wrangler folder. Do you see this folder?
dog1283
dog1283OP5mo ago
OMG that is totally it! no I have a separate DB folder with all my scripts and a separate toml file (same content) Thank you, Harshil!
harshil1712
harshil17125mo ago
Glad that we found the issue!
Want results from more Discord servers?
Add your server