django-postgresql

How to use ArrayField in Django using PostgreSQL DB?

别说谁变了你拦得住时间么 提交于 2019-12-10 20:26:39
问题 I want to do this import in my django models.py: from django.contrib.postgres.fields import ArrayField I read this documentation https://docs.djangoproject.com/en/dev/ref/contrib/ and I added 'django.contrib.postgres' into my INSTALLED_APPS in settings.py, but when I try to sync my db or to runserver I got "ImportError: No module named postgres" Is there something else I should do or install? django.contrib.postgres is part of the core distribution right? This is traceback: Traceback (most

how does CONN_MAX_AGE work in Django

我与影子孤独终老i 提交于 2019-12-10 14:33:39
问题 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 has not been reached), the connection is left open. 4) Request #2 comes in, and Django re-uses connection #1 to the database. But that doesn't seem to be happening. I have a page on my site that does an AJAX poll every 15 seconds. In my development

Django Query extremely slow

社会主义新天地 提交于 2019-12-05 11:40:56
i got a problem with an Django application. Queries on the model Scope are extremly slow and after some debugging i still got no clue where the problem is. When i query the db like scope = Scope.objects.get(pk='Esoterik I') in django it takes 5 to 10 seconds. The database has less than 10 entries and an index on the primary key. so it is way too slow. When executing the an equivalent query on the db like SELECT * FROM scope WHERE title='Esoterik I'; everything is ok, it takes only about 50ms. Same problem happens if i do a query with a set of results like scope_list = Scope.objects.filter

How to start Postgres server? [closed]

谁都会走 提交于 2019-12-02 16:43:56
Ive actually had this problem for a while but I've finally decided to take it on. Postgres was initially installed using Brew. After my upgrade to OSX 10.8.2 to receive a psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? error when I typed the $ psql command. I see the following processes: $ ps auxw | grep post Tulsa 59222 0.0 0.2 2483256 14808 ?? Ss Thu03PM 0:02.61 /System/Library/PrivateFrameworks/DiskImages.framework/Resources/diskimages-helper -uuid 470DA5CC-1602-4D69-855F

Postgres: values query on json key with django

拜拜、爱过 提交于 2019-11-30 20:18:13
I need to do a values/values_list query on nested key on a postgres backed jsonfield in django 1.10 eg. class AbcModel(models.model): context = fields.JSONField() If it has values like: { 'lev1': { 'lev': 2 } } I want to run a queries like AbcModel.objects.values('context__lev1__lev2').distinct() AbcModel.objects.values_list('context__lev1__lev2', flat=True).distinct() EDIT: The JSON fields are the official django JSONField from django.contrib.postgres.fields So I found a solution, this works with django 1.10 and above. I used the KeyTransform to annotate and extract the nexted key and did a

django id integer limit

╄→гoц情女王★ 提交于 2019-11-29 13:27:55
Is there a limit to the AutoField in a Django model or the database back-ends? The Django project I am working on could potentially see a lot of objects in certain database tables which would be in excess of 40000 within a short amount of time. I am using Sqlite for dev and Postgresql for production. Adding this as an answer. Django maps this to serial columns which means that the maximum value is in the 2 billion range ( 2,147,483,647 to be exact). While that is unlikely to be an issue for most applications, if you do, you could alter the type to become a bigint instead and this would make it

django id integer limit

被刻印的时光 ゝ 提交于 2019-11-28 07:14:51
问题 Is there a limit to the AutoField in a Django model or the database back-ends? The Django project I am working on could potentially see a lot of objects in certain database tables which would be in excess of 40000 within a short amount of time. I am using Sqlite for dev and Postgresql for production. 回答1: Adding this as an answer. Django maps this to serial columns which means that the maximum value is in the 2 billion range ( 2,147,483,647 to be exact). While that is unlikely to be an issue