Django 1.8 How Drop certain tables using manage.py?

2.5k views Asked by At

I'm having a real bad time using manage.py to drop certain tables of the database, the project is already running.

the only way I found is accessing the tables by:

python manage.py dbshell

but again, not sure how to drop the tables.

1

There are 1 answers

0
Chris On BEST ANSWER

Django's dbshell drops you into the command-line client for your configured database. Some commands will be database-specific, but dropping tables is pretty consistent across major databases.

Once you're in there you should be able to

DROP TABLE foo;

to drop the foo table. You will probably need to drop tables in a particular order since they may have dependencies on each other, e.g. by foreign key.

(Alternatively you could use the CASCADE parameter to drop dependent tables, but if you're not very careful this could really ruin your night. In my opinion it's better to go slowly and deliberately, dropping one table at a time.)

Of course, always back your database up before doing this kind of thing!