Exercise 1: The Self-Referencing Schema — Possible Solution ==================================================================== THE SCHEMA ------------------------------ // db/schema.ts import { mysqlTable, int, varchar, text, AnyMySqlColumn } from 'drizzle-orm/mysql-core'; export const pages = mysqlTable('pages', { id: int('id').primaryKey().autoincrement(), slug: varchar('slug', { length: 255 }).notNull(), fullPath: varchar('full_path', { length: 1024 }).notNull().unique(), title: varchar('title', { length: 255 }).notNull(), body: text('body'), parentId: int('parent_id').references( (): AnyMySqlColumn => pages.id, { onDelete: 'restrict' } ), }); WHY THE FUNCTION-BASED WORKAROUND IS NEEDED ------------------------------ Per this chapter, references() would normally take a direct reference to another table's column, but pages.id can't be referenced directly from inside the same pages table's own definition - the pages constant doesn't fully exist yet while TypeScript is still evaluating it. Wrapping the reference in an arrow function, (): AnyMySqlColumn => pages.id, defers evaluation until the function is actually called, by which point pages is fully defined. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly defines every column from the chapter's own schema, and correctly explains why the self-referencing foreign key needs a function wrapper rather than a direct column reference.