Delete table and recreate

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

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:

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.

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.

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.

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.

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.)