Questions tagged [django-postgresql]

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

207 questions
8
votes
0 answers

django database routing with transactions

Referring to the example in Django documentation for multiple databases in one application, https://docs.djangoproject.com/en/dev/topics/db/multi-db/#an-example " It also doesn’t consider the interaction of transactions with the database utilization…
kanishk
  • 713
  • 4
  • 15
  • 31
7
votes
1 answer

Django - Using PostGIS database with PostgreSQL database, do I need 2 databases?

I'm currently using a single PostgreSQL database, with standard settings. DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD':…
Valachio
  • 1,025
  • 2
  • 18
  • 40
7
votes
2 answers

Adding a SearchVectorField to a model in Django

So I'm trying to add a SearchVectorField to a model in Django: class JobPosting(models.Model): ... ... search_vector = SearchVectorField() I get that it should either be nullable or have a default value to be able to migrate so I…
7
votes
0 answers

how does CONN_MAX_AGE work in Django

can someone ELI5 what CONN_MAX_AGE does? I thought it worked like this: 1) Request #1 comes in, opens connection 1 to database 2) Request #1 uses connection 1 to do some work 3) Request #1 completes. Because CONN_MAX_AGE is non-zero (and the age…
Chris Curvey
  • 9,738
  • 10
  • 48
  • 70
7
votes
0 answers

Django ORM with date_trunk function and timezones

I would like to use date_trunc SQL function but it it doesn't seem to work with timezones. Test 1 with Django : from django.db import connection cursor = connection.cursor() cursor.execute(""" SELECT (date_trunc('day', when_start)) AS "d",…
Aurélien
  • 259
  • 4
  • 12
7
votes
0 answers

Django admin default ordering of custom fields

I have the following django admin exceprt: class TagAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("title",)} list_display = ['title', 'total_videos', 'total_active_videos', 'weight', 'status'] search_fields = ['title'] …
Feras
  • 2,114
  • 3
  • 20
  • 42
7
votes
2 answers

Django Query extremely slow

I have a problem with a Django application. Queries on the model Scope are extremely slow and after some debugging I still have no clue where the problem lies. When I query the db like scope = Scope.objects.get(pk='Esoterik I') it takes 5 to 10…
6
votes
1 answer

Django Query to get count of all distinct values for particular column

I am trying to fetch count of all distinct values in particular column for example I have following table in model name MyModel : Id City vendor 1 Mumbai 2 2 Pune 3 3 Mumbai 1 4 Yavatmal 2 5 Pune 5 I am…
Piyush S. Wanare
  • 4,703
  • 6
  • 37
  • 54
6
votes
2 answers

Django test fail at postgres hstore migration

I am using postgres with my django app and I had manually created the hstore extension in the database. But, when I run tests it tries to create a new database and fails when the hstore extension is not found. I am getting the following…
6
votes
0 answers

postgresql idle connections with django (and gunicorn+gevent)

My stack incudes django (1.4.3), psycopg2 (0.0.3), and postgres (9.1). Additionally, I am using psycogreen.gevent.patch_psycopg because I am serving up my django with gunicorn and gevent. Everything seems pretty happy, but I am getting a lot…
t1m0
  • 735
  • 1
  • 7
  • 14
5
votes
2 answers

How to annotate sum over Django JSONField (Array of objects) data?

I have models sth like this # models.py class MyModel( models.Model ): orders = models.JsonField(null= True, blank=True, default=list) category = models.ForeignKey(Category, on_delete=models.CASCADE) I stored json data in this structure. [ …
5
votes
2 answers

Django Add new record error duplicate key value violates unique constraint "" Django Id doesn't sync with database

I developed a Django Application and it was working correctly, until I did a data migration to the database created by django migration, I migrated the data using an sql script and Pgadmin. Now I have the database full with records but when I am…
Salma
  • 311
  • 1
  • 6
5
votes
0 answers

Use the CYCLE postgres sequence property in DJANGO auto generated ids

I often get the error: error: nextval: reached maximum value of sequence "my_id_seq" in django autogenerated ids. Postgres is able to easily deal with this using the CYCLE attribute of sequences. My current solution is to do this manually…
5
votes
0 answers

Convert Django ORM query with large IN clause to table value constructor

I have a bit of Django code that builds a relatively complicated query in a programmatic fashion, with various filters getting applied to an initial dataset through a series of filter and exclude calls: for filter in filters: if filter['name']…
v_krishna
  • 206
  • 2
  • 6
5
votes
1 answer

store infinity in postgres json via django

I have a list of tuples like below - [(float.inf, 1.0), (270, 0.9002), (0, 0.0)] I am looking for a simple serializer/deserializer that helps me store this tuple in a jsonb field in PostgreSQL. I tried using JSONEncoder().encode(a_math_function) but…
comiventor
  • 3,922
  • 5
  • 50
  • 77
1
2
3
13 14