Questions tagged [django-postgresql]

Use this tag for PostgreSQL issues which are to be solved in accordance with Django coding best practices.

207 questions
1
vote
0 answers

Django not using correct Postgres schema on Heroku

I have a Django app that I need to connect to a schema "new_schema" by default, rather than public. I've managed to get this working on my local instance by running CREATE SCHEMA new_schema; on the local database & then adding into my settings a…
1
vote
1 answer

How to improve Django-PostgreSQL search performance and increase HTML rendering or AJAX response speed?

I am working on a full text search application in django with postgreSQL where the database has about 50k rows currently. I am using SearchRank and TrigramSimilarity and have already implemented SearchVectorField and GIN indexes, but still the…
1
vote
1 answer

Facing issue while migrating from sqllite to postgresql in Django

I am getting below error when I am migrating from django SQLite to PostgreSQL. django.db.utils.ProgrammingError: cannot cast type smallint to boolean LINE 1: ... "merchant_view" TYPE boolean USING "merchant_view"::boolean I am able to see all the…
1
vote
0 answers

Django rest framework and PostgreSQL best practice

I am using Django and PostgreSQL (psycopg2) for one of our web REST API projects. Basically, the app is driven by the django-rest-framework library for all REST API-centric tasks such as authentication, permission, serialization and API views.…
1
vote
1 answer

django jsonField filtering to get list of values from a specified key

I am storing millions of jsonFields as a field in my django model with the following structure: for object #1: { "key_1": value1 } for object #2: { "key_1": value2 } and so on... How can I get an array of the values for key 1 simply…
user13752552
1
vote
0 answers

Django/PostgreSQL: How to get PostgreSQL hint using django.db.connections and the cursor() function

I am using Django for my app backend. Due to a legacy database, I had to write custom helper functions that execute raw SQL queries. I have this particular rollback function that I wrote and I want to be able to get the RAISE EXCEPTION USING HINT…
Michael
  • 335
  • 1
  • 22
1
vote
0 answers

Using postgres bigserial as autoincrement id field and pk with a more recent version of django

I want to be able to use the bigserial data type for the pk of my django model. I do not want to do it manually with each model i create. Is there any way to change django to use bigserial instead of the serial datatype? All the searches i have done…
1
vote
2 answers

group by integer range Django & posgres

i have a table which i would like to group by integer range (ages). table for example: Name Age John 21 Steve 24 Dan 29 Mike 31 my expected result is to group the name by age ranges for example [21-28] [29-33] so what i'll get is the…
gil
  • 2,388
  • 1
  • 21
  • 29
1
vote
2 answers

Django filter geometry given a coordinate

I want to get a row from a postgis table given a coordinate/point. With raw sql I do it with: SELECT * FROM parcelas WHERE fk_area=152 AND ST_contains(geometry,ST_SetSRID(ST_Point(342884.86705619487, 6539464.45201204),32721)); The query before…
1
vote
1 answer

How to create Django models with ManyToMany relation with tables in different PostgreSQL schemas, one model using just part of unmanaged table

I have a Django application which works just fine. Problem is that it needs to be migrated and that brings some changes. Whole application used to be in PostgreSQL schema intake. Problem is with following models. class Authority(models.Model): …
Rob
  • 41
  • 5
1
vote
1 answer

Django relation does not exist when running test

I'm using Django 2.2.3 and Postgres. I'm trying to add tests into the project and constantly running into an error django.db.utils.ProgrammingError: relation "auth_group" does not exist at test db creation step, when doing either python ./manage.py…
1
vote
1 answer

Saving new django model object gives duplicate key

Django 2.2.3 on Python 3.7, with Amazon RDS Postgres Database. Saving a new object doesn't work for this Company model: class Company(models.Model): name = models.CharField(max_length=255, unique=True) comp =…
Nick Lothian
  • 1,427
  • 1
  • 15
  • 31
1
vote
1 answer

Select the fastest time for each athlete

I'm trying to generate a list of the best result of each athlete, ordered on time. Currently I'm just throwing out every duplicate result after getting all results and ordering on time. I have the following two models: class Athlete(models.Model): …
1
vote
2 answers

What is the difference between annotations and regular lookups using Django's JSONField?

You can query Django's JSONField, either by direct lookup, or by using annotations. Now I realize if you annotate a field, you can all sorts of complex queries, but for the very basic query, which one is actually the preferred method? Example: Lets…
darkhorse
  • 8,192
  • 21
  • 72
  • 148
1
vote
1 answer

How to retrieve all values inside Django Postgres Array Field?

I used Django ArrayField with Postgres Database, I read the documentation however I cannot find a method to retreive all values saved inside the array field. After retrieved the record from database, I want to convert ArrayField type into python…
Kelvin
  • 32
  • 6