Anyone get D1 working with local

Anyone get D1 working with local development? I've tried every blog post and looked through here and can't seem to figure it out. I would be happy with developing against the remote DB or local DB. Every time I'm in dev mode it seems to be connecting to an empty Sqlite DB that doesn't have any tables in it based on the errors. I've tried putting my remote DB name/ID in the bindings or a local one and i get the same results.
setupDevBindings({
persist: true,
bindings: {
DB: {
type: "d1",
id: "local-test-db",
databaseName: "coaching",
}
}
});
setupDevBindings({
persist: true,
bindings: {
DB: {
type: "d1",
id: "local-test-db",
databaseName: "coaching",
}
}
});
6 Replies
alrightsure
alrightsureOPβ€’10mo ago
Ok I finally figured it out (as soon as I posted in here of course). Apparently the "databaseName" attribute in next-on-pages equates to the "(preivew_)database_id" attribute in wrangler.toml, NOT the "database_name" attribute. Kind of baffling that this isn't documented, but I have it working now.
Dario
Darioβ€’10mo ago
@alrightsure I'm very sorry that was my mistake πŸ™‡ I totally understand your confusion and you are totally right! I've already got a "fix" for it which just hasn't been released in which we do provide a warning about the inconsistency: https://github.com/cloudflare/next-on-pages/pull/639 We're also planning to just read the wrangler.toml file very soon, removing this issue altogether: https://github.com/cloudflare/next-on-pages/pull/648 I can totally imagine your confusion (and frustration)! so sorry about that again 😒
alrightsure
alrightsureOPβ€’10mo ago
Awesome no worries at all! Now that I’ve got that figured out it’s been smooth sailing and the deployed performance is really impressive. Thanks for replying and clarifying!
Donnager
Donnagerβ€’10mo ago
O_O that looks amazing!!!
Dario
Darioβ€’10mo ago
Awesome! thanks so much for the understanding! πŸ™ I'm glad that after that hurdle things are working great for you! ❀️ (if you'll have other issues I am always here and on GitHub to help! πŸ˜ƒ) Thanks! ❀️ With the toml file you can get bindings both in the standard dev server and wrangler pages dev without needing to re-define them multiple times (once in the next.config.js and once in the package.json pages script). So yeah hopefully it should be much more convenient! πŸ˜ƒ However the toml file is not read by Pages when you deploy your application so for production you do still need to declare your bindings in the dashboard, it is a bit annoying but hopefully not terrible πŸ™‚ (and the Cloudflare team is looking into improving things)
Donnager
Donnagerβ€’10mo ago
wow! sounds like a major DX win! totally makes sense and good to know, the toml is great from my n00b perspective cause i got majorly tripped up the first time, i think this will make things super smooth for anyone new coming in, can't wait for this to merge!!
Want results from more Discord servers?
Add your server