- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将生产数据库恢复到我的本地计算机,类似于为 Heroku ( https://devcenter.heroku.com/articles/heroku-postgres-import-export) 描述的工作流程。但是,我使用的是 Aptible,它提供了一个 DB tunnel为此目的。
使用 pgAdmin4,我创建了一个“自定义”备份。然后,稍微修改 pgAdmin 命令,我使用
恢复了它"/Applications/pgAdmin 4.app/Contents/SharedSupport/pg_restore" --host "localhost" --port "5432" --username "postgres" --no-password --dbname "lucy_prod" --verbose "/Users/kurtpeek/lucy-prod-backup-11-june-2018" --clean
我在其中添加了 --clean
选项以在重新创建数据库对象之前删除它们(参见 https://www.postgresql.org/docs/9.2/static/app-pgrestore.html )。
问题是,当我现在尝试 python manage.py migrate
时,出现以下错误:
(venv) Kurts-MacBook-Pro-2:lucy-web kurtpeek$ python manage.py migrate
Traceback (most recent call last):
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.ProgrammingError: no schema has been selected to create in
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 57, in ensure_schema
editor.create_model(self.Migration)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 303, in create_model
self.execute(sql, params or None)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 120, in execute
cursor.execute(sql, params)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: no schema has been selected to create in
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
^
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 83, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 52, in __init__
self.build_graph()
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/migrations/loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/Users/kurtpeek/Documents/Dev/lucy2/lucy-web/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 59, in ensure_schema
raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc)
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in
LINE 1: CREATE TABLE "django_migrations" ("id" serial NOT NULL PRIMA...
^
)
据我了解 MigrationSchemaMissing(Unable to create the django_migrations table (%s) % exc) , 我需要跑
grant usage on schema public to username;
grant create on schema public to username;
但是,用户名
应该填什么呢?这应该是 postgres
吗?
这里有一些关于public
模式和search_path
的更多细节:
(venv) Kurts-MacBook-Pro-2:lucy-web kurtpeek$ python manage.py dbshell
psql (10.4)
Type "help" for help.
lucy_prod=> \dn+ public
List of schemas
Name | Owner | Access privileges | Description
--------+----------+-------------------+------------------------
public | postgres | | standard public schema
(1 row)
lucy_prod=> SHOW search_path;
search_path
-----------------
"$user", public
(1 row)
更新
通过运行 select current_user;
命令,我确定我当前的用户名为 lucyapp
,但是如果我尝试grant usage on schema public
对于这个用户,我得到一个“权限被拒绝”的错误:
lucy_prod=> select current_user;
current_user
--------------
lucyapp
(1 row)
lucy_prod=> grant usage on schema public to lucyapp;
ERROR: permission denied for schema public
lucy_prod=> grant create on schema public to lucyapp;
ERROR: permission denied for schema public
最佳答案
这是由于角色对 public
模式的访问问题而发生的。在数据库 shell 中运行此脚本将解决问题。
GRANT ALL ON SCHEMA public TO your_user;
GRANT ALL ON SCHEMA public TO public;
This is for Postgres DB. A similar script can be found for other SQL DB.
关于 Django "MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50805996/
SO对此错误有很多疑问,但我无法摆脱它。我正在尝试将 Django 应用程序连接到 MySQL 数据库,但不断收到此错误: raise MigrationSchemaMissing("Unable
我的数据库中没有有值(value)的数据,无法迁移,如您在此处所见: ResetDjango postgresql database? flush does not work 我尝试使用以下方法重置数
我做的步骤:1.删除迁移文件。2.只创建了一个初始迁移文件。3. 输入 psql 命令提示符。连接到数据库。删除架构公共(public)级联;创建公共(public)模式;4.再次尝试迁移。 我收
所以我使用 MySQL 而不是 SQlite 构建了一个简单的应用程序,当我在本地主机上部署时一切都很好地迁移,本地主机数据库设置如下所示: # DATABASES = { # 'defaul
我正在尝试将生产数据库恢复到我的本地计算机,类似于为 Heroku ( https://devcenter.heroku.com/articles/heroku-postgres-import-exp
我用谷歌搜索了这个问题。有很多类似的问题,但我找不到合适的答案。 这是错误日志的详细信息: Traceback (most recent call last): File "manage.py",
我是一名优秀的程序员,十分优秀!