you're trying to insert 0 as a foreign key?
you're trying to insert 0 as a foreign key?
FOREIGN KEY constraint failed




wrangler d1 info <dbname> will tell youwrangler d1 info <dbname> for that DB?Failed to reach database. Please try again later. and when trying to access the url, it says the DB has just been successfully created. Any tips?FOREIGN KEY constraint failedCREATE TABLE IF NOT EXISTS carts (
id INTEGER PRIMARY KEY,
cartId INTEGER NOT NULL,
branchId INTEGER NOT NULL,
name TEXT NOT NULL,
productId INTEGER NOT NULL,
price REAL NOT NULL, -- << HERE
size TEXT NOT NULL,
quantity TEXT NOT NULL,
customerNotes TEXT NOT NULL DEFAULT '',
discount REAL,
discountName TEXT,
discountDescription TEXT DEFAULT '',
discountEndDate REAL,
createdBy INTEGER NOT NULL,
createdAt REAL NOT NULL,
updatedBy INTEGER,
updatedAt REAL,
status INTEGER NOT NULL,
FOREIGN KEY (branchId) REFERENCES branches(id),
FOREIGN KEY (cartId) REFERENCES cartIds(id),
FOREIGN KEY (productId) REFERENCES products(id),
FOREIGN KEY (createdBy) REFERENCES users (id),
FOREIGN KEY (updatedBy) REFERENCES users (id)
);//hooks.server.ts
import { drizzle } from 'drizzle-orm/d1';
const injectD1 = async (event: RequestEvent<Partial<Record<string, string>>, string | null>) => {
try {
if (event.platform?.env?.DATABASE) {
event.locals.DRIZZLE = drizzle(event.platform.env.DATABASE);
event.locals.D1 = event.platform.env.DATABASE;
}
...
} catch (error) {
console.log('🚀 ~ file: hooks.server.ts:27 ~ consthandle:Handle= ~ error:', error);
}
};