   "Mark primary-key `Fields` for TABLE as `special_type = id` if they don't already have a `special_type`."
   {:arglists '([table])}
   [{table-name :name table-id :id :keys [db pk_field]}]
-  (->> (sel :many :fields [Field :name :id] :table_id table-id :special_type nil :name [in (table-pk-names @db table-name)])
-       (map (fn [{field-name :name field-id :id}]
-              (log/info (format "Field '%s.%s' is a primary key. Marking it as such." table-name field-name))
-              (upd Field field-id :special_type :id)))
-       dorun))
+  (try
+    (->> (sel :many :fields [Field :name :id] :table_id table-id :special_type nil :name [in (table-pk-names @db table-name)])
+         (map (fn [{field-name :name field-id :id}]
+                (log/info (format "Field '%s.%s' is a primary key. Marking it as such." table-name field-name))
+                (upd Field field-id :special_type :id)))
+         dorun)
+    (catch Throwable e
+      (log/error "Caught exception in set-table-pks-if-needed!:" e))))
 
 
 ;; ## SET TABLE FKS

   This is only done for Fields that do not already have a `special_type`."
  {:arglists '([korma-table field])}
  [korma-table {field-name :name field-id :id special-type :special_type}]
  (when-not special-type
    (let [cardinality (-> korma-table
                          (select (aggregate (count (sqlfn :DISTINCT (keyword field-name))) :count))
                          first
                          :count
                          int)]
      (when (< cardinality low-cardinality-threshold)
        (log/info (format "Field '%s.%s' has %d unique values. Marking it as a category." (:table korma-table) field-name cardinality))
        (upd Field field-id :special_type :category)))))


;; ### Check For Large Avg Length

   This is only done for textual fields, i.e. ones with `special_type` of `:CharField` or `:TextField`."
  {:arglists '([korma-table field])}
  [korma-table {base-type :base_type, field-id :id, preview-display :preview_display, :as field}]
  (try
    (when (and preview-display                                 ; if field is already preview_display = false, no need to check again since there is no case
               (contains? #{:CharField :TextField} base-type)) ; where we'd end up changing it.
      (let [avg-len (field-avg-length korma-table field)]
        (when (> avg-len average-length-no-preview-threshold)
          (log/info (format "Field '%s.%s' has an average length of %d. Not displaying it in previews." (:table korma-table) (:name field) avg-len))
          (upd Field field-id :preview_display false))))
    (catch Throwable e
      (log/error "Caught exception in check-for-large-average-length:" e))))


;; ### Check for URLs
