在“DROP SCHEMA public”之后无法创建新表。 [英] Cannot create a new table after "DROP SCHEMA public"
问题描述
由于我想删除一些表,有人建议下面,我做到了:
Since I wanted to drop some tables and somebody suggested the below and I did it:
postgres=# drop schema public cascade;
DROP SCHEMA
postgres=# create schema public;
CREATE SCHEMA
然后我在创建新数据库时遇到问题,如:
Then I got problem when creating a new database, such as:
postgres=# create database test;
CREATE DATABASE
postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# create table hi(id int primary key);
*ERROR: no schema has been selected to create in*
错误
错误:尚未选择在*中创建模式
ERROR: no schema has been selected to create in*
如何恢复公共模式?
我建议人们不要做drop schema public cascade;如果我们不知道如何恢复。有人可以帮助我吗?
How can I restore the public schema?
I suggest people never do "drop schema public cascade;" if we don't know how to restore. Can somebody help me out?
推荐答案
当 search_path
可以找到。
它是错误配置。
The error message pops up when none of the schemas in your search_path
can be found.
Either it is mis-configured. What do you get for this?
SHOW search_path;
或者您已删除了 public
标准系统数据库 template1
。当您运行 drop schema public cascade时,您可能已连接到错误的数据库;
Or you deleted the public
schema from your standard system database template1
. You may have been connected to the wrong database when you ran drop schema public cascade;
顾名思义,这是创建新数据库的模板。因此,每个新数据库开始时没有(默认)模式 public
现在 - 而您的默认 search_path
'in it。
As the name suggests, this is the template for creating new databases. Therefore, every new database starts out without the (default) schema public
now - while your default search_path
probably has 'public' in it.
只要运行(以超级用户 public
或参见 mgojohn的回答):
Just run (as superuser public
or see mgojohn's answer):
CREATE SCHEMA public;
template1
db
通过 DROP SCHEMA ... CASCADE
删除其中的所有对象很快就是有效的。
The advice with DROP SCHEMA ... CASCADE
to destroy all objects in it quickly is otherwise valid.
这篇关于在“DROP SCHEMA public”之后无法创建新表。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!