我有一个预先构建的 django 项目,需要在 ubuntu 18 上运行它。使用 postgresql 作为数据库引擎,完成并安装了所有先决条件。为项目创建了一个数据库并添加了具有所需权限的用户,然后将这些设置更新到 settings.py
文件
然后我运行了以下命令来准备迁移并实现它。
# python manage.py makemigrations
No changes detected
&
# python manage.py migrate
Traceback (most recent call last):
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: permission denied to create extension "postgis"
HINT: Must be superuser to create this extension.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 77, in handle
connection.prepare_database()
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 26, in prepare_database
cursor.execute("CREATE EXTENSION IF NOT EXISTS postgis")
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/hsn/env_banax_api/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: permission denied to create extension "postgis"
HINT: Must be superuser to create this extension.
你们中有人知道如何修复它吗? Django 服务器正在运行,但我得到的是这个页面,我想这与数据库连接有关。 附上当前显示的页面截图。
最佳答案
您可以做的是:使用postgres super 用户
在您的数据库中创建postgis 扩展
。
使用 super 用户名(您在安装 postgresql 时提供的用户名)登录到 postgres shell:
sudo -i -u < super 用户用户名> psql
连接到您的数据库:
\connect <数据库名称>
将 postgis 扩展创建为:
创建扩展 postgis;
可以了解用户权限here如果您在创建扩展时遇到权限问题。
关于django - 预构建的 Django 项目在迁移时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56055805/