6

I'm trying to drop a single table from my App's database in a Django project. When I enter the database shell using manage.py dbshell, I try to execute DROP TABLE mytable; and get ERROR: table "mytable" does not exist I think the cause of this stems from the database thinking I'm in my project directory instead of my app directory but I don't know how to change that.

This is what the shell looks like after I type ./manage.py dbshell:

myproject=# DROP TABLE mytable; ERROR: table "mytable" does not exist

I think instead of myproject=# it should say something like myapp=# or myproject/myapp=# but I do not know how to accomplish this.

3
  • Why don't you use postgresql console ? Commented Apr 4, 2018 at 7:40
  • 1
    remove corresponding models from models.py and do migration Commented Apr 4, 2018 at 7:42
  • Removing the model from model.py will force me to also remove any (or most) references to that model in my code before I can see if it works. It'll be tedious but I may do that as a last resort. Commented Apr 4, 2018 at 8:04

1 Answer 1

23

After accessing your local db via: sudo -i -u postgres

Or python manage.py dbshell

Try typing \l to see what databases do you actually have

Then \dt to see a list of relations

And then DROP TABLE some_table;

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for your response. I after typing in those commands, the only relevant database that shows up is in fact the MyProject database. Am I only able to delete this?
Well there must be several databases including the database of your django project, others are a standard postgresql databases, you might delete them as well, but there is no point in doing so
Let me know if there are some other issues
You were correct! I was looking at the wrong layout. At the bottom of the \dt output was the myapp_mytable name that I needed to type in to delete it. I was simply typing the incorrect name. Thank you very much for your help! I was stuck on this for awhile.
thanks :) DROP TABLE public."some_table"; worked for me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.