加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL中 drop table指令出现ERROR: cannot drop table user

发布时间:2020-12-13 17:08:28 所属栏目:百科 来源:网络整理
导读: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 it DETAIL: con

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 it DETAIL: constraint userid on table signinlog depends on table userinfo constraint userid on table sleepreport depends on table userinfo HINT: 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)

//删除table
blue=# DROP TABLE userinfo CASCADE;
NOTICE:  drop cascades to 2 other objects DETAIL: drop cascades to constraint userid on table signinlog drop cascades to constraint userid on table sleepreport DROP 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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读