```sql -- Migration number: 0000 2024-01-29T06:07:39.777Z CREATE TABLE searchLogs ( id INT

-- Migration number: 0000      2024-01-29T06:07:39.777Z

CREATE TABLE searchLogs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ip TEXT,
    type TEXT NOT NULL CHECK (type IN ('BLID', 'NAME')),
    query TEXT NOT NULL
);


I have this searchLogs table. The createdAt is a datetime that defaults to the current timestamp.
Youd think this would be valid but when I try to insert:
async function logSearch(DB: D1Database, ip: string, type: string, search: string) {
  try {
    const logSearchQuery = /*sql*/ `INSERT INTO searchLogs(ip, type, query) VALUES(?, ?, ?)`;
    await DB.prepare(logSearchQuery).bind(ip, type.toUpperCase(), search).run();
  } catch (error) {
    console.error("Failed to log search:", error);
  }
}


I get this error:
✘ [ERROR] Failed to log search: Error: D1_ERROR: NOT NULL constraint failed: searchLogs.createdAt                                                                                                                                                
[1]
[1]       at D1Database._sendOrThrow (cloudflare-internal:d1-api:66:19)
[1]       at async D1PreparedStatement.run (cloudflare-internal:d1-api:172:29)

???

Was this page helpful?