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: Select one row for each unique value of a field (column)

I have the following model in my Django application; I want to get a queryset of my model with only one row for every unique value of a field (I do not care which row that would be at this point). The problem is I cannot use the distinct function,…
Paris
  • 6,323
  • 7
  • 31
  • 49
1
vote
1 answer

Annotate one part of a range to a new field

So we've been using a DateTimeRangeField in a booking model to denote start and end. The rationale for this might not have been great —separate start and end fields might have been better in hindsight— but we're over a year into this now and there's…
Oli
  • 235,628
  • 64
  • 220
  • 299
1
vote
0 answers

OuterRef not allowed in an annotation?

I'm trying to annotate a queryset of Entity objects with the distance between two related polygons; each entity has its own set of related polygons, stored in the shape attribute of foreign-key-related EntityFeature objects. EntityFeatures are…
bribroder
  • 86
  • 6
1
vote
1 answer

django/postgresql setup - psycopq2.OperationalError

I'm getting a 'psycopq2.OperationalError' when executing: python manage.py syncdb. The postgresql server seems to be up and running when tested with a djangostack script. Anyone run across this? Just going through the django tutorial and setting…
Igor
  • 63
  • 1
  • 1
  • 6
1
vote
0 answers

could not translate host name "postgres" to address

I use PostreSQL and Django 1.8 in my app. I have an error: django.db.utils.OperationalError: could not translate host name "postgres" to address: nodename nor servname provided, or not known but I cannot find a please where host name "postgres" is…
v18o
  • 1,237
  • 2
  • 15
  • 25
1
vote
2 answers

Permission denied error with PostgreSQL and Django. Giving rights to PostgreSQL user admin

I have Django app with PostgreSQL. The app has those environment variables: DATABASE_HOST=localhost DATABASE_USER=admin DATABASE_PASSWORD=admin Here is psql output: postgres=# CREATE USER admin WITH PASSWORD 'admin123'; ERROR: role "admin" already…
v18o
  • 1,237
  • 2
  • 15
  • 25
1
vote
1 answer

DjangoRestFrameWork filter one model from another

I have a model with an ArrayField called "participants". I can't have the array be a list of users due to the limitations of postgress' ArrayField. Due to this, I have stored the usernames as strings in the array. Now I want to serialize the user…
IzPrEE
  • 183
  • 2
  • 13
1
vote
1 answer

Django with PostgreSQL 10?

Does Django support PostgreSQL 10 at the moment? I tried to use pgadmin3 with the psql V10 and found, it breaks pdagmin3. Somebody has opened a ticket on django project which may be in discussion. Is there any known breaking changes in v10 compared…
All Іѕ Vаиітy
  • 24,861
  • 16
  • 87
  • 111
1
vote
1 answer

Django PostgreSQL IntegerRangeField and update_or_create

I have a pretty simple model: from django.contrib.postgres.fields import IntegerRangeField from django.db import models class Production(models.Model): title = models.CharField(max_length=100, blank=True, db_index=True) year =…
Michael Samoylov
  • 2,933
  • 3
  • 25
  • 33
1
vote
0 answers

Why does the Django 'PostgreSQL Full Text Search' not return my objects and how to fix it?

I can't get the PostgreSQL Full Text Search feature to work as I need it. I have a model Vereinwith a field straße. There are two Verein objects where straße has the value "Uhlandstraße". What I want to achieve is that a search for "Uhl", "uhl",…
Daniel
  • 3,092
  • 3
  • 32
  • 49
1
vote
0 answers

ArrayAgg() returns string representation, not list

Hoping I could annotate a QuerySet with an array aggregate, I tried the following: Item.objets.annotate( results=ArrayAgg( RawSQL("row(field_a, field_b)", []), output_field=ArrayField(ArrayField(models.IntegerField()))) …
jnns
  • 5,148
  • 4
  • 47
  • 74
1
vote
0 answers

On heroku, Migrating from Sqllite3 to Postgres in Django

Here is what I am trying to do python manage.py dumpdata > database.json Changing my setting files: from DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), …
1
vote
1 answer

Postgresql date_trunc called in custom function through Django's connection.cursor()

I created a custom Postgresql function that performs some calculations and determines the beginning of a month by using the date_trunc function. When developing the custom function, I checked it from within a database connection established with…
1
vote
1 answer

Optimization of bulk update/insert

I'm writing a web application that is going to show player statistics for an online game, using Django 1.6 and PostgreSQL 9.1. I've created a script using django-extensions "runscript" which fetches all players that are online and insert/updates…
simon
  • 2,042
  • 2
  • 20
  • 31
1
vote
0 answers

Django query slow on profiler but fast on PostgreSQL

Django-live-profiler is showing me a query executed a huge number of time with a slow average time. So the total execution time of the request is high. When I execute the same request directly on PostgreSQL, the query is very fast to execute (less…
poiuytrez
  • 21,330
  • 35
  • 113
  • 172