In order to completely uninstall a Django application you have to not only delete the database tables - but you also need to remove the related contenttypes.
Let's look at two ways to handle this: Manually and with South.
In this case, the application name is called
customers, and it contains the following tables within models.py:
1 2 3 4 5 6 7 8 9 10 11 12
Also, I am using a sqlite3 database called test.db, which contains this data.
Let's say we want to drop the Course table (for reasons unknown).
- Navigate to your project working directory and drop the table:
Remove the app from the INSTALLED_APPS section in settings.py and delete any associated URL patterns from urls.py.
Drop the database tables:
equivalent MySQL command -
$ mysql -u root -p <database_name> < drop_<app_name>_<table_name>.sql
- Clean up the related contenttypes from the Shell:
1 2 3
- You can now delete the app folder as well as any associated media files and/or templates. Finally, make sure to uninstall any associated packages or dependencies using
pip uninstall <package_name>. Make sure to use virtualenv.
I use South with all my Django projects, so I tend to prefer this method. Let's take a look.
- Setup the initial migration and push it through:
CustomerProfileclass from models.py.
Setup the migration to delete the table:
- Update the migration file 0002autodelcustomerprofile.py, to clean up the related contenttypes as well as delete the table from the database, by updating the
1 2 3 4 5
- Push the migration through:
- Fake a zero migration to remove the migration history and clear up the South tables:
- Remove the app from the INSTALLED_APPS section in settings.py and delete any associated URL patterns from urls.py. Then delete the app folder and any related media files and/or templates. Finally, make sure to uninstall any packages or dependencies using
pip unistall <package_name>. Make sure to use virtualenv.
Comment if you have questions. Cheers!