All Questions
3,768 questions
1
vote
0
answers
52
views
Optimizing Django ORM for Hybrid Queries (PostgreSQL + Vector Similarity Search)
I'm implementing a RAG (Retrieval-Augmented Generation) system that requires combining traditional Django ORM filtering with vector similarity searches. The specific workflow needs to:
First filter ...
0
votes
0
answers
33
views
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf3 in Django connection with PostgreSQL in Docker
I am trying to connect my Django application to PostgreSQL running in a Docker container, but when I execute python manage.py runserver or python manage.py makemigrations, I get the following error:
...
2
votes
1
answer
53
views
Django models migration gets generated after managed set to False [duplicate]
In my django project, I have 2 databases, and I'm trying to achieve a cross database foreign key relationship. the models Form, FormSubmission, CmsEvent are in a postgres database and the models ...
0
votes
0
answers
49
views
How does one correctly define an index for efficiently querying the reverse relation for ForeignKey fields? (when starting from parent.related_set)
FINAL EDIT: Okay, I've been asked to refine my question to as someting more specific/concrete. So here is the question:
Given the following model definitions:
class ParentModel(models.Model):
# ...
1
vote
0
answers
65
views
Why does duplicating a Django filter condition change PostgreSQL’s query plan estimates?
I'm working on a Django project with PostgreSQL and have implemented a custom filter to select "active" records. The filter is defined as follows:
def get_custom_filter(qs):
return qs....
0
votes
3
answers
88
views
How to find server_version in psycopg3?
I have this test in Django [1] which is using psycopg2:
from django.db import connection
def test_postgresql_version(self):
postgresql_version = connection.cursor().connection.server_version
...
0
votes
1
answer
55
views
How to migrate Django from local sqlite3 to postgresql Docker container?
I'm trying to learn Django with some demo projects and want to migrate from sqlite3 to a local postgresql container for dev work. When I try to run uv run python manage.py migrate, I get the following ...
0
votes
2
answers
135
views
Ordering data after distinct
I distinct data by sku_id
queryset = self.filter_queryset(queryset.order_by('sku_id','id').distinct('sku_id'))
However this result is not sorted by id,
then I try to
queryset = self....
0
votes
1
answer
152
views
Intermittent Pooler Error in django app server
facing intermittent Pooler Error: server conn crashed? in my http server. Tried searching and fixing long running transaction in my system but didn't help. Also this happens very randomly at any point ...
1
vote
2
answers
77
views
Django 5.1 + Postgresql (debian server)
Trying to connect to posgresql base as Django wrote in its docs:
https://docs.djangoproject.com/en/5.1/ref/databases/#postgresql-notes
DATABASES = {
"default": {
"ENGINE&...
-1
votes
2
answers
373
views
Unable to use psycopg2 with Postgres in Django
As stated in my question, I am now configuring my djagno project to connect with postgres. The issue i am facing is that, when making migrations, it shows me the following error:
python manage.py ...
0
votes
1
answer
28
views
Django + FactoryBoy -> Postgres not converting datetime to utc correctly
Okay, this is a weird one. I've got a Django model that I'm writing to Postgres via FactoryBoy for testing.
contract = ContractFactory(
effective_date=datetime.datetime(2023, 1, 1, tzinfo=...
1
vote
1
answer
210
views
Callable default on unique field will not generate unique values upon migrating
Using Django/DRF to create a CRUD api
I'm trying to use the RandomUUID to create a UUID from Postgres:
from django.db import models
from django.contrib.postgres.functions import RandomUUID
class Year(...
0
votes
1
answer
54
views
How do I convert a complex Postgres SQL query into a Django queryset?
I have the following SQL query working:
SELECT
mrc.token_id,
ARRAY_AGG(mt.name) AS tracking
FROM
markets_rankscurrent mrc
LEFT JOIN (
SELECT
mtg.id,
mtg.index_id,
...
1
vote
2
answers
71
views
Constraint to forbid NaN in postgres numeric columns using Django ORM
Postgresql allows NaN values in numeric columns according to its documentation here.
When defining Postgres tables using Django ORM, a DecimalField is translated to numeric column in Postgres. Even if ...