ALTER TABLE inventory_transactions ADD COLUMN IF NOT EXISTS department_id INT NULL; ALTER TABLE inventory_transactions ADD CONSTRAINT fk_inventory_dept FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE SET NULL;