Django迁移错误:Django.db.utils.ProgrammingError:必须是关系库的所有者

2024-05-16 15:00:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我对本地版本的站点做了一些更改,将模型推送到服务器,并进行了makemigration

(revampenv) sammy@samuel-pc:~/revamp$ python manage.py makemigrations gallery
Migrations for 'gallery':
  0032_auto_20170829_0058.py:
    - Create model Area
    - Create model Color
    - Create model ThumbnailCache
    - Add field unique_key_string to image
    - Alter field example on image
    - Alter field timeline on image

工作很好,然后我试图迁移,我得到了这个错误

^{pr2}$

我以前也遇到过这样或类似的错误,当时数据库数据库数据库下面有一个本地env的副本,但现在不是这样了。在

(注意)其他型号也不适用

(revampenv) sammy@samuel-pc:~/revamp$ python manage.py makemigrations account
Migrations for 'account':
  0003_userprofile_bio.py:
    - Add field bio to userprofile


(revampenv) sammy@samuel-pc:~/revamp$ python manage.py migrate
  ...
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be owner of relation account_userprofile

更新 试图编辑数据库所有者

postgres=# ALTER DATABASE color_db OWNER TO revamp;
ALTER DATABASE

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'color_db',
        'USER': 'revamp',
        'PASSWORD': 'xxx',
        'HOST': 'localhost',
        'PORT': '',
    }
}

但它仍然返回相同的错误

(revampenv) sammy@samuel-pc:~/revamp$ python manage.py migrate
...
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be owner of relation account_userprofile

Tags: pyimage数据库fielddbmodelmanagecreate
1条回答
网友
1楼 · 发布于 2024-05-16 15:00:44

您需要将当前用户设置为数据库所有者。为此,您需要打开postgres shell并执行查询:

ALTER DATABASE name OWNER TO new_owner

请参阅详细信息here。在

相关问题 更多 >