psycopg2.errors.InsufficientPrivilege:关系 django_migrations 的权限被拒绝 [英] psycopg2.errors.InsufficientPrivilege: permission denied for relation django_migrations
问题描述
我的数据库 settings.py 是什么样的:
What my settings.py for DB looks like:
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fishercoder',
'USER': 'fishercoderuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
我以这种方式创建了一个名为fishercoder"的新的空数据库:
I have created a new and empty db named "fishercoder" this way:
psql -U postgres
create database fishercoder;
ALTER USER postgres with password 'badpassword!';
CREATE USER fishercoderuser WITH PASSWORD 'password';
ALTER ROLE fishercoderuser SET client_encoding TO 'utf8';
ALTER ROLE fishercoderuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE fishercoderuser SET timezone TO 'PST8PDT';
GRANT ALL PRIVILEGES ON DATABASE fishercoder TO fishercoderuser;
然后我通过运行:psql -U postgres fishercoder < 成功地将我的其他 SQL 转储导入到这个新的数据库中.fishercoder_dump.sql
然后我尝试在这个 EC2 实例上的我的 Django 项目上运行 ./manage.py makemigrations
,但是得到这个错误:
Then I tried to run ./manage.py makemigrations
on my Django project on this EC2 instance, but got this error:
Traceback (most recent call last):
File "/home/ubuntu/myprojectdir/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.InsufficientPrivilege: permission denied for relation django_migrations
I found these three related posts on SO: One, two and three
我尝试了他们建议的命令:
I tried the commands they suggested:
postgres=# GRANT ALL ON ALL TABLES IN SCHEMA public to fishercoderuser;
GRANT
postgres=# GRANT ALL ON ALL SEQUENCES IN SCHEMA public to fishercoderuser;
GRANT
postgres=# GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to fishercoderuser;
GRANT
不走运,然后我重新启动了我的 postgresql 数据库:sudo service postgresql restart
当我再次尝试运行迁移时,仍然面临同样的错误.
no luck, I then restarted my postgresql db: sudo service postgresql restart
when I tried to run migrations again, still faced w/ the same error.
更多调试信息如下:
ubuntu@ip-xxx-xxx-xx-xx:~$ psql -U postgres
Password for user postgres:
psql (10.12 (Ubuntu 10.12-0ubuntu0.18.04.1))
Type "help" for help.
postgres=# \dt django_migrations
Did not find any relation named "django_migrations".
postgres=# \d django_migrations
Did not find any relation named "django_migrations".
postgres=# \dp django_migrations
Access privileges
Schema | Name | Type | Access privileges | Column privileges | Policies
--------+------+------+-------------------+-------------------+----------
(0 rows)
postgres=# SHOW search_path; \dt *.django_migrations
search_path
-----------------
"$user", public
(1 row)
Did not find any relation named "*.django_migrations".
postgres=# \dn+ public.
List of schemas
Name | Owner | Access privileges | Description
--------------------+----------+----------------------+----------------------------------
information_schema | postgres | postgres=UC/postgres+|
| | =U/postgres |
pg_catalog | postgres | postgres=UC/postgres+| system catalog schema
| | =U/postgres |
pg_temp_1 | postgres | |
pg_toast | postgres | | reserved schema for TOAST tables
pg_toast_temp_1 | postgres | |
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
(6 rows)
任何想法如何解决这个问题?
Any ideas how to fix this?
推荐答案
请尝试使用以下命令,这对我有用
Please try using the below command, this worked for me
GRANT rds_superuser TO username;
这篇关于psycopg2.errors.InsufficientPrivilege:关系 django_migrations 的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!