Fis*_*der 15 python database django postgresql amazon-ec2
我的数据库 settings.py 看起来像:
ALLOWED_HOSTS = ['*']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fishercoder',
'USER': 'fishercoderuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '5432',
}
}
Run Code Online (Sandbox Code Playgroud)
我这样创建了一个名为“fishercoder”的新空数据库:
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;
Run Code Online (Sandbox Code Playgroud)
然后我通过运行以下命令成功地将其他 SQL 转储导入到这个新数据库中:psql -U postgres fishercoder < fishercoder_dump.sql
然后我尝试./manage.py makemigrations在此 EC2 实例上运行我的 Django 项目,但收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
我尝试了他们建议的命令:
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
Run Code Online (Sandbox Code Playgroud)
不走运,然后我重新启动了我的 postgresql 数据库:sudo service postgresql restart
当我尝试再次运行迁移时,仍然面临相同的错误。
更多调试信息如下:
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)
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决这一问题?
小智 23
我有以下错误。
psycopg2.errors.InsufficientPrivilege:表 django_migrations 的权限被拒绝
向与我一起工作的用户授予超级用户“postgres”的权限。
对我来说,这个命令有效:
GRANT postgres TO <user>;
恢复数据库后,所有表将归postgres用户所有。
您需要执行此补助金:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO <user>;
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题并且解决了。
您还需要向 Django 用户授予其他权限:
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO <user>;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16251 次 |
| 最近记录: |