2017-08-07 105 views
0

我是新來的Django,我試圖使用Django(1.8)在Postgres的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遷移我得到​​

以下是堆棧跟蹤

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

settings.py有DB連接如下面的conf

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

您是否創建了與您的django用戶作爲所有者的postgres數據庫? –

+0

我通過shel安裝postgres時創建了db,現在我想通過django連接到那個db,並在表 –

+0

中創建並插入數據你可以測試本地連接'psql -h localhost -U xyz abc'? –

回答

1

可能是你需要讓分站賽給您的用戶:

GRANT ALL ON DATABASE abc TO xyz; 
+0

它工作,感謝 –

0

我不會建議對所有做GRANT。但是,正如Bear Brown指出的那樣,這聽起來像是權限問題,所以請確保您至少具有相關架構的USAGE和表的SELECT特權。首先連接到abc數據庫,然後授予公共選擇特權:

GRANT SELECT ON ALL TABLES IN SCHEMA public TO xyz