ProgrammingError:关系 django_session 的权限被拒绝

Posted

技术标签:

【中文标题】ProgrammingError:关系 django_session 的权限被拒绝【英文标题】:ProgrammingError: permission denied for relation django_session 【发布时间】:2014-08-19 20:53:09 【问题描述】:

我最近在网站上遇到了 500 个错误。错误是ProgrammingError: permission denied for relation django_session

update_disable() ajax 函数有时会发生这种情况。

这里是函数

def update_disable(request, song_pk, dj_name=None, view=None, genre=None):
    song = Song.objects.get(pk=song_pk)
    song.votes = song.votes + 1
    song.save()
    dajax = Dajax()
    dajax.assign('.vote', 'disabled', 'disabled')
    if dj_name:
        request.session[dj_name] = True
    elif genre:
        print genre
        request.session[genre] = True
    else:
        if view=="month":
            request.session['month_voted'] = True
        else:
            request.session['trending_voted'] = True
    request.session.set_expiry(604800)
    visitor = get_obj_or_none(Visitor, last_session_key=request.session._session_key)
    if visitor:
        voter = get_obj_or_none(Voter, visitor=visitor)
        if voter:
            voter.vote_count += 1
            voter.save()
        else:
            voter = Voter(visitor=visitor)
            voter.save()
    return dajax.json()

我似乎无法理解引发此错误的原因。有什么想法吗?

这是整个回溯

Traceback (most recent call last):

  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 201, in get_response
    response = middleware_method(request, response)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sessions/middleware.py", line 38, in process_response
    request.session.save()

  File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py", line 63, in save
    obj.save(force_insert=must_create, using=using)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 545, in save
    force_update=force_update, update_fields=update_fields)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 573, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 654, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 687, in _do_insert
    using=using, raw=raw)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 232, in _insert
    return insert_query(self.model, objs, fields, **kwargs)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 1511, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 899, in execute_sql
    cursor.execute(sql, params)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)

  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)

ProgrammingError: permission denied for relation django_session



<WSGIRequest
path:/dajaxice/hunt.update_disable/,
GET:<QueryDict: >,
POST:<QueryDict: u'argv': [u'"song_pk":"680","dj_name":"Tiesto"']>,
COOKIES:'_ga': 'GA1.2.1299003573.1404006039',
'csrftoken': '**masked**',
META:'CONTENT_LENGTH': '67',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
u'CSRF_COOKIE': u'**masked**',
'HTTP_ACCEPT': '*/*',
'HTTP_ACCEPT_ENCODING': 'gzip,deflate,sdch',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
'HTTP_CONNECTION': 'close',
'HTTP_COOKIE': 'csrftoken=**masked**; _ga=GA1.2.1299003573.1404006039',
'HTTP_HOST': 'www.edmhunters.com',
'HTTP_ORIGIN': 'http://www.edmhunters.com',
'HTTP_REFERER': 'http://www.edmhunters.com/top100/tiesto/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
'HTTP_X_CSRFTOKEN': '**masked**',
'HTTP_X_FORWARDED_FOR': '110.32.33.39',
'HTTP_X_FORWARDED_PORT': '80',
'HTTP_X_FORWARDED_PROTO': 'http',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
'HTTP_X_REQUEST_ID': 'ebadfe5f-d375-460d-8bdf-8a879f8fb13b',
'HTTP_X_REQUEST_START': '1404006080594',
'PATH_INFO': u'/dajaxice/hunt.update_disable/',
'QUERY_STRING': '',
'RAW_URI': '/dajaxice/hunt.update_disable/',
'REMOTE_ADDR': '10.122.102.62',
'REMOTE_PORT': '34465',
'REQUEST_METHOD': 'POST',
'SCRIPT_NAME': u'',
'SERVER_NAME': 'www.edmhunters.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.1',
'SERVER_SOFTWARE': 'gunicorn/18.0',
'gunicorn.socket': <socket._socketobject object at 0x35882f0>,
'wsgi.errors': <open file '<stderr>', mode 'w' at 0x7fcd37a971e0>,
'wsgi.file_wrapper': <class gunicorn.http.wsgi.FileWrapper at 0x244e1f0>,
'wsgi.input': <gunicorn.http.body.Body object at 0x35bc550>,
'wsgi.multiprocess': False,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)>

【问题讨论】:

您使用的是哪个数据库? @BurhanKhalid PostreSQL checkout你的数据库权限,好像你没有权限在django-session表中执行了一条sql, 【参考方案1】:

如果您使用 Heroku PostgreSQL 作为数据库,您可能已达到行数限制。用命令行工具验证一下:

heroku pg:info -a &lt;your_app&gt;

=== HEROKU_POSTGRESQL_MAUVE_URL, DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           0/20
PG Version:            10.6
Created:               2018-03-14 22:04 UTC
Data Size:             20.3 MB
Tables:                90
Rows:                  13764/10000 (Write access revoked)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Billing App:           xxxxxxxxx
Add-on:                postgresql-silhouetted-xxx

Rows: 行告诉您写访问权限已被撤销:(Write access revoked)

【讨论】:

遇到这个问题,请问有解决办法吗 @AzeezBello 您需要升级您的数据库计划以增加容量或删除内容。【参考方案2】:

如果您使用的是 Heroku、DJANGO、PostgreSQL

这个错误被解释为by Heroku here

heroku 提供的用于解决此问题的所有方法都需要您更新帐户。 为了避免这一切,我想告诉你如何解决这个问题

1.在本地机器上安装 POSTGRESSQL Heroku devcenter tutorial

2。获取您的 BATABASE 信息

$ heroku pg:info -a your-app-name

=== DATABASE_URL
Plan:                  Hobby-dev
Status:                Available
Connections:           6/20
PG Version:            11.12
Created:               2019-09-10 23:20 UTC
Data Size:             11.8 MB
Tables:                33
Rows:                  1064/10000 (In compliance)
Fork/Follow:           Unsupported
Rollback:              Unsupported
Continuous Protection: Off
Add-on:                postgresql-********

注意最后一行(附加组件)我们将使用它

3.打开您的在线 PSQL 命令提示符

$ heroku pg:psql postgresql-******** --app your-app-name

将 '********' 替换为您的插件内容*

如果一切顺利,您已到达应用程序的 pqsl 命令提示符

4.删除 django_session 表

your-app-name::DATABASE=> DROP TABLE django_session;

5.创建一个新的 django_session 表

your-app-name::DATABASE=> CREATE TABLE django_session (
   session_key     varchar(40),
   session_data   text,
   expire_date timestamptz );

6.退出

your-app-name::DATABASE=> \q

【讨论】:

以上是关于ProgrammingError:关系 django_session 的权限被拒绝的主要内容,如果未能解决你的问题,请参考以下文章

django.db.utils.ProgrammingError: 关系已经存在于 OenBSD vps

/ 关系“main_post”处的 ProgrammingError 不存在

django.db.utils.ProgrammingError:关系“users_user”不存在

解决“django.db.utils.ProgrammingError: 关系 django_migrations 的权限被拒绝”的步骤

使用 South 在 Heroku 上设置 Django 时遇到问题 - 不断出现 ProgrammingError:关系不存在

Django ProgrammingError:在 Django 源代码中创建迁移后,关系已经存在?