Django loaddata返回拒绝关联的权限 [英] Django loaddata returns a permission denied for relation

查看:28
本文介绍了Django loaddata返回拒绝关联的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Django项目中的dumpdata生成的json文件中的某些数据加载到使用loaddata的具有新数据库的新文件中.与数据库的连接似乎正常工作,但是几乎立即我收到关系django_content_type的权限被拒绝.我没有得到我们正在谈论的许可.该数据库是一台位于单独服务器上的postgres,我通过我的笔记本电脑上的一个无聊的虚拟机连接到它,该虚拟机具有虚拟环境,并且settings.py具有用于连接到数据库的设置.这是回溯:

I am trying to load some data from a json file generated from a dumpdata on a django project to a new one with a new database using loaddata. The connection to the db seems to work but almost right away I receive a permission denied for relation django_content_type. I don't get what permission we are talking about. the db is postgres on a separate server and I connect to it through a vagrant virtual machine on my laptop that has a virtual environment and the settings.py has the settings to connect to the db. Here is the Traceback:

Problem installing fixture 'djgprd1_dumpdata.json': Traceback (most recent call last):
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 196, in handle
    obj.save(using=using)
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/core/serializers/base.py", line 165, in save
    models.Model.save_base(self.object, using=using, raw=True)
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/db/models/base.py", line 524, in save_base
    manager.using(using).filter(pk=pk_val).exists())):
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/db/models/query.py", line 565, in exists
    return self.query.has_results(using=self.db)
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 441, in has_results
    return bool(compiler.execute_sql(SINGLE))
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/home/vagrant/devenv/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
DatabaseError: Could not load contenttypes.ContentType(pk=29): permission denied for relation django_content_type

我在做什么错了?

推荐答案

此数据库的postgres用户是自动创建的,我没有检查权限,因为缺少该数据库的权限,所以 GRANT ALL PRIVILEGES ON DATABASEx代表用户y; 解决了权限问题.我不好.

The postgres user for this db was created automatically and I did not check the permissions, they were missing for this db so a GRANT ALL PRIVILEGES ON DATABASE x for user y; resolved the permissions problem. My bad.

这篇关于Django loaddata返回拒绝关联的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆