# Delete table and recreate

**URL:** <https://forum.djangoproject.com/t/delete-table-and-recreate/40448>\
**Category:** Using the ORM\
**Created:** [April 16, 2025, 1:20pm UTC](https://forum.djangoproject.com/t/delete-table-and-recreate/40448 "2025-04-16T13:20:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbhrfx9280](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jbhrfx9280/32/15247_2.png) [@jbhrfx9280](https://forum.djangoproject.com/u/jbhrfx9280)\
**Post date:** [April 16, 2025, 1:20pm UTC](https://forum.djangoproject.com/t/delete-table-and-recreate/40448/1 "2025-04-16T13:20:11Z")

</div>

Django 5.1.7  
Postgresql 14.17

I need to remove a table from my database and then recreate (migrate) it back. Tried everything i can find in django docs and online. Nothing works. I tried all the zero and fake options etc.  
Whats also interesting is if i remove all the apps migration files and drop the table manually from the db Django will NOT recreate the table using makemigrations / migrate commands. I have even commented out all references in the models.py file and just causes errors.

Please someone advise on this. Can’t be this hard or convoluted to do this.  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![leandrodesouzadev](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/leandrodesouzadev/32/8981_2.png) [@leandrodesouzadev](https://forum.djangoproject.com/u/leandrodesouzadev)\
**Post date:** [April 16, 2025, 1:30pm UTC](https://forum.djangoproject.com/t/delete-table-and-recreate/40448/2 "2025-04-16T13:30:26Z")

</div>

> [@jbhrfx9280](#):
>
> Nothing works

That’s quite vague.  
Normally what I do when I need to remove a table is using the migrate command specifying the migration that was created before the one that has created the table.  
For example:  
If you have the following migrations: `0001_initial` and `0002_alter_field` and you want to revert all changes that were introduced, then you would do the following command:  
`python manage.py <your_app_name> zero`

But if this is your scenario:  
You have the following migrations: `0001_initial` and `0002_create_model_foo` and you want to revert the migration that added the `Foo` model, that was introduced on the `0002` migration, then you would do the following command:  
`python manage.py <your_app_name> 0001`

Otherwise, this other approach that you’ve tried shall also work:

> [@jbhrfx9280](#):
>
> Whats also interesting is if i remove all the apps migration files and drop the table manually from the db Django will NOT recreate the table using makemigrations / migrate commands

Have you also deleted the row that applied the migration on the `django_migrations` table on your database? The one that has the `CreateModel` operation? If you delete the table manually, you need to also remove the row that tells django that the specific migration has already been executed.

If you need a more specific answer, please provide more details about your setup: models, existing migrations and what migration has introduced the model that you want to delete.

---

<div class="post-metadata">

**Author:** ![jbhrfx9280](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jbhrfx9280/32/15247_2.png) [@jbhrfx9280](https://forum.djangoproject.com/u/jbhrfx9280)\
**Post date:** [April 16, 2025, 2:00pm UTC](https://forum.djangoproject.com/t/delete-table-and-recreate/40448/3 "2025-04-16T14:00:03Z")

</div>

Yes, i did try the zero option and removing previous migrations. Did not work. Isnt removing all the migration files going to try and recreate the table? It does not.  
Thank you for replying.

---

<div class="post-metadata">

**Author:** ![jbhrfx9280](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jbhrfx9280/32/15247_2.png) [@jbhrfx9280](https://forum.djangoproject.com/u/jbhrfx9280)\
**Post date:** [April 16, 2025, 2:59pm UTC](https://forum.djangoproject.com/t/delete-table-and-recreate/40448/4 "2025-04-16T14:59:40Z")

</div>

SOLUTION:  
Okay, I figured out the process on how to remove a table from the database unapply the migrations and, re-create the table. This seems to work every time.  
NOTE : Cannot find this process as laid out anywhere as of yet. Hmmm

Step 1, run  
py manage.py showmigrations  
Now find your app and notice the current migrations.

Step 2, we’re going to delete the current or unapply the current migrations.  
Run command  
py manage.py migrate --fake zero  
Notice the feedback from running this command that it is showing unapply all migrations and the name of your app etc…

Step 3, delete all the migration files for that app.  
Note, these files will be in your migrations folder for that app.

Step 4, do  
py manage.py showmigrations  
again and find your app and make sure that it shows no migrations.

Step 5 You need to go to your database and delete or drop the table. You can manually refresh your tables if necessary to make sure that table is indeed dropped..

Step 6, from Django run your make migrations and migrate commands to recreate your table.

You should now see your table recreated in the database, and you will also see a 0001\_initial.py migrations file has also been created within Django migrations folder?

Done.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 16, 2025, 3:12pm UTC](https://forum.djangoproject.com/t/delete-table-and-recreate/40448/5 "2025-04-16T15:12:27Z")

</div>

> [@jbhrfx9280](#):
>
> Okay, I figured out the process on how to remove a table from the database unapply the migrations and, re-create the table. This seems to work every time.

This process should not be a general recommendation.

If you’re going to use the migrations module, then allow _it_ to manage your database.

If you’re going to try to manage your database manually, then don’t use migrations.

Mixing the two is prone to creating hard-to-resolve conflicts.

> [@jbhrfx9280](#):
>
> Step 3, delete all the migration files for that app.  
> Note, these files will be in your migrations folder for that app.

This is a dangerous step. If you have another app that identifies ones of these migrations as a prerequisite, you risk breaking your entire migration structure.

**If** you are going to delete _any_ migrations in your project, you should plan on deleting them _all_, and rerunning makemigrations for all apps in your project. (You also want to ensure that the migrations table is emptied. You should then be able to run your initial migration with the `fake` option.)
