How do I drop a table from SQLite3 in DJango?


Database Problem Overview

I made a model, and ran python syncdb. I think that created a table in the db. Then I realized that I had made a column incorrectly, so I changed it, and ran the same command, thinking that it would drop the old table, and add a new one.

Then I went to python shell, and tried to run .objects.all(), and it failed, saying that column doesn't exist.

I want to clear out the old table, and then run syncdb again, but I can't figure out how to do that.

Database Solutions

Solution 1 - Database

to clear out an application is as simple as writing:

./ sqlclear app_name | ./ dbshell 

then in order to rebuild your tables just type:

./ syncdb

Solution 2 - Database

None of the answers shows how to delete just one table in an app. It's not too difficult. The dbshell command logs the user into the sqlite3 shell.

python dbshell

When you are in the shell, type the following command to see the structure of your database. This will show you all the table names in the database (and also the column names within tables).

SELECT * FROM sqlite_master WHERE type='table';

In general, Django names tables according to the following convention: "appname_modelname". Therefore, SQL query that accomplishes your goal will look similar to the following:

DROP TABLE appname_modelname;

This should be sufficient, even if the table had relationships with other tables. Now you can log out of SQLITE shell by executing:


If you run syncdb again, Django will rebuild the table according to your model. This way, you can update your database tables without losing all of the app data. If you are running into this problem a lot, consider using South - a django app that will migrate your tables for you.

Solution 3 - Database

Another simple way to do this while using Django 1.4 or below, would be

python reset app_name

which drops and re-creates the tables used by the models of this app.

This was deprecated in Django 1.3 and is no longer available from Django 1.5

Solution 4 - Database

get the DROP statements with

python sqlclear app_name

then try

python dbshell

and execute the DROP statement

check out

Solution 5 - Database

I had the same problem.

For a quick resolve (if you don't care about losing your tables/data), correct your file with the desired data types, delete the Migration folder and db.SQLite3 file,

then re-run the following commands:

  1. python migrate

  2. python makemigrations

  3. python migrate

  4. python createsuperuser (to create an admin user/pswd to manage admin page)

  5. python runserver

Solution 6 - Database

In Django 2.1.7, I've opened the db.sqlite3 file in SQLite browser (there is also a Python package on Pypi) and deleted the table using command

DROP TABLE appname_tablename;

and then

DELETE FROM django_migrations WHERE App='appname';

Then run again

python makemigrations appname
python migrate appname

Solution 7 - Database

In Django 1.9 I had to do Kat Russo's steps, but the second migration was a little bit tricky. You have to run

./ migrate --run-syncdb

Solution 8 - Database

Might be worth expanding on a few answers here:

So, you can get access to the dbshell with the following command:

python dbshell

It is then preferential to use the following:

DROP TABLE appname_tablename CASCADE;

To drop any related tables, effectively mirroring the "on_delete=CASCADE" direction on a field.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - DatabaseAdrián DeccicoView Answer on Stackoverflow
Solution 2 - DatabaseiamioView Answer on Stackoverflow
Solution 3 - DatabaseOfri RavivView Answer on Stackoverflow
Solution 4 - DatabaseGeorge GodikView Answer on Stackoverflow
Solution 5 - DatabaseKat RussoView Answer on Stackoverflow
Solution 6 - DatabasePremysl VoracView Answer on Stackoverflow
Solution 7 - DatabaseSchdiewie KayView Answer on Stackoverflow
Solution 8 - DatabaseMicheal J. RobertsView Answer on Stackoverflow