    This only applies to textual fields that *do not* already have a `special_type.`"
   {:arglists '([korma-table field])}
   [korma-table {special-type :special_type, base-type :base_type, field-name :name, field-id :id, :as field}]
-  (when (and (not special-type)
-             (contains? #{:CharField :TextField} base-type))
-    (let [percent-urls (field-percent-urls korma-table field)]
-      (when (> percent-urls percent-valid-url-threshold)
-        (log/info (format "Field '%s.%s' is %d%% URLs. Marking it as a URL." (:table korma-table) field-name (int (math/round (* 100 percent-urls)))))
-        (upd Field field-id :special_type :url)))))
+  (try
+    (when (and (not special-type)
+               (contains? #{:CharField :TextField} base-type))
+      (let [percent-urls (field-percent-urls korma-table field)]
+        (when (> percent-urls percent-valid-url-threshold)
+          (log/info (format "Field '%s.%s' is %d%% URLs. Marking it as a URL." (:table korma-table) field-name (int (math/round (* 100 percent-urls)))))
+          (upd Field field-id :special_type :url))))
+    (catch Throwable e
+      (log/error "Caught exception in check-for-urls:" e))))

  "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))


;; ## SET TABLE FKS

  "Mark foreign-key `Fields` for TABLE as `special_type = fk` if they don't already have a `special_type`."
  {:arglists '([korma-table table])}
  [korma-table {database :db table-name :name table-id :id}]
  (try
    (let [fks            (table-fks @database table-name)
          fk-name->id    (sel :many :field->id [Field :name] :table_id table-id :special_type nil :name [in (map :fk-column-name fks)])
          table-name->id (sel :many :field->id [Table :name] :name [in (map :dest-table-name fks)])]
      (->> fks
           (map (fn [{:keys [fk-column-name dest-column-name dest-table-name]}]
                  (when-let [fk-column-id (fk-name->id fk-column-name)]
                    (when-let [dest-table-id (table-name->id dest-table-name)]
                      (when-let [dest-column-id (sel :one :id Field :table_id dest-table-id :name dest-column-name)]
                        (log/info (format "Marking foreign key '%s.%s' -> '%s.%s'." table-name fk-column-name dest-table-name dest-column-name))
                        (ins ForeignKey
                          :origin_id fk-column-id
                          :destination_id dest-column-id
                          :relationship (determine-fk-type korma-table fk-column-name))
                        (upd Field fk-column-id :special_type :fk))))))
           dorun))
    (catch Throwable e
      (log/error "Caught exception in set-table-fks-if-needed!:" e))))


;; ### Check for Low Cardinality
