我是Django的新手,我正在尝试使用Django(1.8)在Postgre中创建表格
以下是我的模型类
class Student(models.Model):
name = models.CharField(max_length = 50)
degree = models.CharField(max_length = 50)
numofsubs = models.IntegerField()
namesofsubs= models.CharField(max_length = 50)
details = models.CharField(max_length = 50)
class Meta:
db_table = "student"
views.py
def addStudent(request):
student = Student(name = request.name, degree = request.degree ,
numofsubs = request.numofsubs , nameofsubs = request.nameofparams , details = request.details)
student.save()
print 'data saved'
在我尝试运行python manage.py migrate之后发生这些更改后,我得到了django.db.utils.ProgrammingError: permission denied for relation django_migrations
以下是堆栈跟踪
回溯(最近一次呼叫最后一次):文件" manage.py",第10行,in execute_from_command_line(sys.argv)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/ init .py&#34 ;, 第338行,在execute_from_command_line中 utility.execute()文件" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/ init .py" , 第330行,执行中 self.fetch_command(子命令).run_from_argv(self.argv)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/base.py" ;, 第390行,在run_from_argv中 self.execute(* args,** cmd_options)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/base.py", 第441行,执行中 output = self.handle(* args,** options)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py& #34 ;, 第93行,处理中 executor = MigrationExecutor(connection,self.migration_progress_callback)文件 " /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/executor.py" ;, 第19行,在 init 中 self.loader = MigrationLoader(self.connection)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/loader.py", 第47行,在 init 中 self.build_graph()File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/loader.py", 第180行,在build_graph中 self.applied_migrations = recorder.applied_migrations()File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", 第60行,在applied_migrations中 在self.migration_qs.values_list中返回set(tuple(x)for x(" app"," name"))文件 " /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/query.py" ;, 第162行, iter self._fetch_all()File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/query.py", 第965行,在_fetch_all中 self._result_cache = list(self.iterator())File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/query.py" , 1220行,在迭代器中 对于compile.results_iter()中的行:File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", 第783行,在result_iter中 results = self.execute_sql(MULTI)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", 第829行,在execute_sql中 cursor.execute(sql,params)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/backends/utils.py", 第79行,执行中 return super(CursorDebugWrapper,self).execute(sql,params)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/backends/utils.py 34 ;, 第64行,执行中 return self.cursor.execute(sql,params)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/utils.py", 第97行,在退出 six.reraise(dj_exc_type,dj_exc_value,traceback)File" /usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/backends/utils.py", 第64行,执行中 return self.cursor.execute(sql,params)django.db.utils.ProgrammingError:关系权限被拒绝 django_migrations
我的settings.py
有关于db conection的后续配置
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'abc',
'USER': 'xyz',
'PASSWORD': 'xxxxx',
'HOST': 'localhost',
'PORT': 5432,
}
}
请指导我的应用程序有什么问题。
由于
答案 0 :(得分:1)
您可能需要允许您的用户使用以下内容:
GRANT ALL ON DATABASE abc TO xyz;
答案 1 :(得分:0)
我不建议做全部的。但是,正如Bear Brown指出的那样,这听起来像是权限,所以请确保您至少拥有相关模式的USAGE和表的SELECT权限。首先连接到abc数据库,然后在public上授予select权限:
GRANT SELECT ON ALL TABLES IN SCHEMA public TO xyz