You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*Turn`validate` off for id-based upserts. `activerecord-import` runs
266
-
uniqueness validations against the very rows the upsert is about to overwrite,
267
-
so a model-level `validates_uniqueness_of` would otherwise reject the update.
254
+
* Only the columns you list are updated; other columns on the existing row keep their values.
255
+
* Use `validate: false` — `activerecord-import` runs uniqueness validations against the very rows the upsert is about to overwrite, so `validates_uniqueness_of` would otherwise reject the update.
268
256
* Active Record callbacks are not fired for bulk imports.
269
257
258
+
###### Delete-then-insert (any database)
259
+
260
+
When you can't rely on upsert support — an older database, or you need your model
261
+
validations to run — delete the colliding rows just before each batch insert.
262
+
The old row is gone before the insert, so `validates_uniqueness_of` doesn't trip,
263
+
at the cost of a second query and full-row **replacement** (columns absent from
0 commit comments