PostgreSQL中 drop table指令出现ERROR: cannot drop table userinfo because other objects depend on it

来源:互联网 发布:网络科学引论 编辑:程序博客网 时间:2024/05/17 06:46

PostgreSQL中 drop table指令出现ERROR: cannot drop table userinfo because other objects depend on it。

blue=# drop table userinfo; //删除table指令//错误信息提示ERROR:  cannot drop table userinfo because other objects depend on itDETAIL:  constraint userid on table signinlog depends on table userinfoconstraint userid on table sleepreport depends on table userinfoHINT:  Use DROP ... CASCADE to drop the dependent objects too.

问题分析:
出现这个问题的原因在于,登录数据的用户和创建这个table的用户不是同一个用户,所以存在这么一个问题。下面我们打印出数据库中的表的信息。

打印数据库中的表(PS:指令:“\d”)

blue=# \d   //查看数据库中的表             List of relations Schema |    Name     | Type  |    Owner    --------+-------------+-------+------------- public | deviceinfo  | table | sxw public | signinlog   | table | sxw public | sleepreport | table | sxw public | userinfo    | table | postgres(4 rows)

参考资料:
官方网站关于DROP出现问题的分析

内容截图如下:

内容截图

使用指令:(PS: blue=#指当前是名字为blue的数据库)

blue=# DROP TABLE userinfo CASCADE;//删除table指令

下面将我删除table的操作以及\d查询的结果粘贴如下:

//删除table之前 \d 查看数据库中的表blue=# \d              List of relations Schema |    Name     | Type  |    Owner    --------+-------------+-------+------------- public | deviceinfo  | table | sxw public | signinlog   | table | sxw public | sleepreport | table | sxw public | userinfo    | table | postgres(4 rows)//删除tableblue=# DROP TABLE userinfo CASCADE;NOTICE:  drop cascades to 2 other objectsDETAIL:  drop cascades to constraint userid on table signinlogdrop cascades to constraint userid on table sleepreportDROP TABLE//删除后,\d 查看数据库中的表blue=# \d             List of relations Schema |    Name     | Type  |    Owner    --------+-------------+-------+------------- public | deviceinfo  | table | sxw public | signinlog   | table | sxw public | sleepreport | table | sxw(3 rows)
0 0