sqldatabasepostgresqlsql-dropdrop-table

Cannot drop table users because other objects depend on it


I want to drop my tables in my database. But, when I use, for example, DROP TABLE if exists users; I receive this message:

cannot drop table users because other objects depend on it

I found the solution is to drop all tables. But, anyway, how to solve this problem without total data removal?


Solution

  • Use the cascade option:

    DROP TABLE if exists users cascade;
    

    this will drop any foreign key that is referencing the users table or any view using it.

    It will not drop other tables (or delete rows from them).