预构建的 Django 项目在迁移时出错
pre-built django project gives error on migrate
我有一个预构建的 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 服务器是 运行ning,但我得到的是这个页面,我想这与数据库连接有关。
附上现在显示的页面截图。
您可以做的是:使用 postgres superuser
.
在您的数据库中创建 postgis extension
使用超级用户用户名(您在安装 postgresql 时提供的用户名)登录到 postgres shell:
sudo -i -u < superuser_username > psql
连接到您的数据库:
\connect < database_name >
将 postgis 扩展创建为:
创建扩展 postgis;
如果您在创建扩展时遇到权限方面的问题,您可以了解用户权限 here。
我有一个预构建的 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 服务器是 运行ning,但我得到的是这个页面,我想这与数据库连接有关。 附上现在显示的页面截图。
您可以做的是:使用 postgres superuser
.
postgis extension
使用超级用户用户名(您在安装 postgresql 时提供的用户名)登录到 postgres shell:
sudo -i -u < superuser_username > psql
连接到您的数据库:
\connect < database_name >
将 postgis 扩展创建为:
创建扩展 postgis;
如果您在创建扩展时遇到权限方面的问题,您可以了解用户权限 here。