Django ORM PostgreSQL

Django ORM PostgreSQL

Explore django orm postgresql code snippets and tutorials

Django ORM PostgreSQL

Bulk upsert (INSERT ... ON CONFLICT DO UPDATE)

bulk_create(update_conflicts=True, unique_fields=[...], update_fields=[...]) compiles to INSERT ...

Django ORM PostgreSQL

Migration operations (code only — run at migrate time)

These run during migrate, not in queries, so there's no result row — only the Django code and the SQL it emits.

Django ORM PostgreSQL

Concurrency & EXPLAIN

select_for_update() issues SELECT ...

Django ORM PostgreSQL

Indexes (GIN, GiST, SP-GiST, BRIN, B-tree, Hash, partial, covering)

Indexes live in a model's Meta.indexes; migrations emit the CREATE INDEX DDL shown below (read live from pg_indexes).

Django ORM PostgreSQL

More lookups (contained_by, range bounds, has_keys, trigram word)

The remaining lookup variants: __contained_by (arrays/json/ranges — the inverse of __contains), __fully_gt, range bound transforms like __lower_inc, JSON __has_keys/__has_any_keys, and __trigram_word_similar (a fuzzy word match inside a longer string).