1

I have rewritten and renamed an entire app. It has now passed my tests, so it is time to delete the old version. To my surprise, this is either much harder than it should be, or I just haven't found the right answer. Where is 'python manage.py delete app 'appname'? I looked at this How to delete a record in Django models? and at the docs https://docs.djangoproject.com/en/4.0/topics/migrations/#workflow.

First I tried just removing the entire app from the filesystem, but migrations complained:

File "/home/malikarumi/.virtualenvs/LogBook/lib/python3.9/site-packages/django/db/models/base.py", line 113, in new raise RuntimeError( RuntimeError: Model class uppergi.models.Food doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. (LogBook) malikarumi@Tetuoan2:~/Projects/LogBook$ python manage.py delete uppergi Unknown command: 'delete' Type 'manage.py help' for usage. (LogBook) malikarumi@Tetuoan2:~/Projects/LogBook$ manage.py help manage.py: command not found (LogBook) malikarumi@Tetuoan2:~/Projects/LogBook$ git revert 8bb60951

So I put it back and tried deleting one model at a time. Migrations complained about that, too.

(LogBook) malikarumi@Tetuoan2:~/Projects/LogBook$ python manage.py makemigrations Traceback (most recent call last): ... File "/home/malikarumi/Projects/LogBook/uppergi/admin.py", line 6, in from . models import Grocer, Food, ShoppingTrip, Cook, Eaten ImportError: cannot import name 'Eaten' from 'uppergi.models' (/home/malikarumi/Projects/LogBook/uppergi/models.py)

and specifying the app:

(LogBook) malikarumi@Tetuoan2:~/Projects/LogBook$ python manage.py makemigrations uppergi Traceback (most recent call last): File "/home/malikarumi/Projects/LogBook/manage.py", line 25, in ... File "/home/malikarumi/Projects/LogBook/uppergi/admin.py", line 6, in from . models import Grocer, Food, ShoppingTrip, Cook, Eaten ImportError: cannot import name 'Eaten' from 'uppergi.models' (/home/malikarumi/Projects/LogBook/uppergi/models.py)

It looks like the only way to do this is to manually undo all the things you do after running startapp: go to urls, got to models, go to views, go to admin, etc. That is of course possible, but not very modular. Is there really no way to do this thoroughly and automatically with one command???

Malik A. Rumi
  • 1,855
  • 4
  • 25
  • 36

1 Answers1

0

In order to avoid migration troubles, I usually delete the files inside the migration folder and __pycache__ folder except init files. This usually works. So, you can go ahead and try deleting these files. For instance, I deleted these files when I had the same issue:

  1. Files under the __pycache__ folder
  2. Files under the migrations folder

Try running migrations again and see if this works.

onapte
  • 217
  • 2
  • 8