© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•2y ago•
4 replies
Taylor

Working with D1 Remote DB locally with nextjs

So i'm using Cloudflare D1, I imported data into my remote Cloudflare D1 database, i didn't do this for the --local one and i don't really want to if possible. I want to just locally develop with the remote database. I have my binding setup and i created an API route like this
import type { NextRequest } from "next/server";
import { getRequestContext } from "@cloudflare/next-on-pages";
import { cases } from "@/schema";
import { CloudflareEnv } from "@/env";
import { db } from "@/db";

export const runtime = "edge";

export async function GET(request: NextRequest, env: CloudflareEnv) {
  const context = getRequestContext();

  const DB = db((context.env as CloudflareEnv).edendb);

  const result = await DB.select({
    CaseID: cases.CaseID,
    CasePriority: cases.CasePriority,
    CaseStatus: cases.CaseStatus,
    Pending: cases.Pending,
    Active: cases.Active,
    Closed: cases.Closed,
    NotReviewed: cases.NotReviewed,
  }).from(cases);

  return new Response(JSON.stringify(result), {
    status: 200,
    headers: {
      "Content-Type": "application/json",
    },
  });
}
import type { NextRequest } from "next/server";
import { getRequestContext } from "@cloudflare/next-on-pages";
import { cases } from "@/schema";
import { CloudflareEnv } from "@/env";
import { db } from "@/db";

export const runtime = "edge";

export async function GET(request: NextRequest, env: CloudflareEnv) {
  const context = getRequestContext();

  const DB = db((context.env as CloudflareEnv).edendb);

  const result = await DB.select({
    CaseID: cases.CaseID,
    CasePriority: cases.CasePriority,
    CaseStatus: cases.CaseStatus,
    Pending: cases.Pending,
    Active: cases.Active,
    Closed: cases.Closed,
    NotReviewed: cases.NotReviewed,
  }).from(cases);

  return new Response(JSON.stringify(result), {
    status: 200,
    headers: {
      "Content-Type": "application/json",
    },
  });
}


I deployed the site with pnpm run deploy

everythings good and when i go to the live url/api/getallcases route,

it works just as expected. But in local development I get a
✘ [ERROR] Error: D1_ERROR: no such table: Cases
✘ [ERROR] Error: D1_ERROR: no such table: Cases



I know this has something to do with the local vs remote database but I can't seem to figure out how to develop against it with Nextjs, could anyone help? I've gotten this error with both pnpm run dev (nextjs server) and pnpm wrangler pages dev
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Cannot Interact with D1 Locally on Cloudflare Pages
Cloudflare DevelopersCDCloudflare Developers / pages-help
2y ago
NextJS Dev Server keeps on crashing with D1
Cloudflare DevelopersCDCloudflare Developers / pages-help
2y ago
Accessing remote D1 database during local dev with SvelteKit
Cloudflare DevelopersCDCloudflare Developers / pages-help
14mo ago
NextJS deployment fails after adding D1 binding
Cloudflare DevelopersCDCloudflare Developers / pages-help
3y ago