没有选择任何模式来创建...错误

时间:2016-12-18 10:00:36

标签: python linux postgresql ubuntu search-path

我正在研究一个托管在amazons服务器上的linux服务器,我已经完全设置了服务器,我要做的最后一件事是托管我在Flask Framework中的服务器上创建的旧项目之一

我正在尝试运行设置运行项目所需的数据库的python文件。

我在服务器内部使用虚拟机运行我的项目,每次运行命令时都会出现以下错误:

(venv) grader@ip-10-20-6-95:/var/www/catalog/catalog$ python setup_database.py
Traceback (most recent call last):
  File "setup_database.py", line 63, in <module>
    Base.metadata.create_all(engine)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/schema.py", line 2848, in create_all
    tables=tables)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1479, in _run_visitor
    conn._run_visitor(visitorcallable, element, **kwargs)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1122, in _run_visitor
    **kwargs).traverse_single(element)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 122, in traverse_single
    return meth(obj, **kw)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/ddl.py", line 70, in visit_metadata
    self.traverse_single(table, create_ok=True)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 122, in traverse_single
    return meth(obj, **kw)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/ddl.py", line 89, in visit_table
    self.connection.execute(schema.CreateTable(table))
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 662, in execute
    params)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 720, in _execute_ddl
    compiled
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 874, in _execute_context
    context)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception
    exc_info
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 196, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 867, in _execute_context
    context)
  File "/var/www/catalog/venv/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 324, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) no schema has been selected to create in
 '\nCREATE TABLE users (\n\tid SERIAL NOT NULL, \n\tusername VARCHAR(100), \n\temail VARCHAR(225) NOT NULL, \n\tprofile_pic VARCHAR(225) NOT NULL, \n\tPRIMARY KEY (id)\n)\n\n' {}

我不知道为什么会收到此错误。
我运行的命令设置PostgreSQL(如果这很重要):

$ sudo apt-get install libpq-dev python-dev
$ sudo apt-get install postgresql postgresql-contrib
$ sudo su - postgres
$ psql
# CREATE USER catalog WITH PASSWORD 'sillypassword';
# ALTER USER catalog CREATEDB;
# CREATE DATABASE catalog WITH OWNER catalog;
# \c catalog
# REVOKE ALL ON SCHEMA public FROM public;
# GRANT ALL ON SCHEMA public TO catalog;
# \q
$ exit

如何解决这个问题?

4 个答案:

答案 0 :(得分:8)

no schema has been selected to create in

search_path设置没有有效的第一个条目(通常为空)时,会出现此错误。 Postgres不知道在哪个模式中创建表。

修复您的search_path设置或架构限定对象名称(例如:public.users)。但请将您的search_path修复为任何案例 详细说明:

答案 1 :(得分:4)

此问题已得到解答:https://dba.stackexchange.com/a/275116/114247

解决方法是:

grant usage on schema public to public;
grant create on schema public to public;

答案 2 :(得分:1)

您没有创建架构。使用 CREATE SCHEMA public; 创建架构 然后你可以执行grant usage on schema public to public;grant create on schema public to public

答案 3 :(得分:0)

我发现$.ajax({ url: "chart.php", method: "POST", data: { diseaseselection: diseaseselection }, dataType: "json", //parse the response data as JSON automatically success: function(data) { Morris.Line({ element: 'chart', data: data, //supply the response data (which is now a JS variable) directly, no extra brackets xkey: 'age', ykeys: ['totalM', 'totalF'], labels: ['Total MALE', 'Total FEMALE'], hideHover: 'auto', pointStrokeColors: ['white'], lineWidth: '6px', parseTime: false, lineColors: ['Skyblue', 'Pink'], }); } }); (在postgres 10.7下)创建的文件具有

pg_dump

靠近它的顶部。因此,在导入文件时,它会操纵搜索路径,该路径在当前会话中一直存在。

评论该行(并开始新的会话)解决了该问题。