Django 1.8 migration error with postgres
我是Django的新手,我正在尝试使用Django(1.8)在Postgre中创建表
以下是我的模型类
1 2 3 4 5 6 7 8 9 10 | 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
1 2 3 4 5 | 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之后发生这些更改后,我得到了
以下是堆栈跟踪
Traceback (most recent call last): File"manage.py", line 10, in
execute_from_command_line(sys.argv) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/init.py",
line 338, in execute_from_command_line
utility.execute() File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/init.py",
line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/base.py",
line 390, in run_from_argv
self.execute(*args, **cmd_options) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/base.py",
line 441, in execute
output = self.handle(*args, **options) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py",
line 93, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback) File
"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/executor.py",
line 19, in init
self.loader = MigrationLoader(self.connection) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/loader.py",
line 47, in init
self.build_graph() File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/loader.py",
line 180, in build_graph
self.applied_migrations = recorder.applied_migrations() File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/migrations/recorder.py",
line 60, in applied_migrations
return set(tuple(x) for x in self.migration_qs.values_list("app","name")) File
"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/query.py",
line 162, in iter
self._fetch_all() File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/query.py",
line 965, in _fetch_all
self._result_cache = list(self.iterator()) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/query.py",
line 1220, in iterator
for row in compiler.results_iter(): File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
line 783, in results_iter
results = self.execute_sql(MULTI) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
line 829, in execute_sql
cursor.execute(sql, params) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/backends/utils.py",
line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/backends/utils.py",
line 64, in execute
return self.cursor.execute(sql, params) File"/usr/lib/ckan/default/local/lib/python2.7/site-packages/django/db/utils.py",
line 97, in exit
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",
line 64, in execute
return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: permission denied for relation
django_migrations
我的
1 2 3 4 5 6 7 8 9 10 11 12 | 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, } } |
请指导我的应用程序有什么问题。
谢谢
您可能需要允许您的用户使用以下内容:
1 | GRANT ALL ON DATABASE abc TO xyz; |
我不建议做一个GRANT ALL。 但是,正如Bear Brown指出的那样,这听起来像是权限,所以请确保您至少拥有相关模式的USAGE和表的SELECT权限。 首先连接到abc数据库,然后在public上授予select权限:
1 | GRANT SELECT ON ALL TABLES IN SCHEMA public TO xyz |