Reputation: 2948
I have an app in my django project that I'd rather do away with. I have removed all models and removed all reference to the app from all other apps but if when I remove the app from my settings.INSTALLED_APPS
I get the below error.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000028F0C408C80>
Traceback (most recent call last):
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\core\management\base.py", line 442, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\db\migrations\loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\db\migrations\loader.py", line 226, in build_graph
self.add_external_dependencies(key, migration)
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\db\migrations\loader.py", line 191, in add_external_dependencies
parent = self.check_key(parent, key[0])
File "C:\Users\Chidimmo\.virtualenvs\funnshopp-Ze7zokAC\lib\site-packages\django\db\migrations\loader.py", line 174, in check_key
raise ValueError("Dependency on unknown app: %s" % key[0])
ValueError: Dependency on unknown app: service
I want to remove every reference to that app from the database as well as removing it from settings.INSTALLED_APPS
.
I performed a search of django docs but couldn't find anything to that effect. All previous solutions I found here on SO relied on sqlclear
which is no longer supported by django.
How should I go about it? I'm using Django==2.1.3
Upvotes: 1
Views: 211
Reputation: 48902
The problem is that your migration files constitute a version history of your project. So if another model once had a ForeignKey
to a model in your deleted app, that reference is still in a migration file somewhere as a dependency.
One solution is to squash migrations and then delete the old files once all the databases are up to date. There are also more extreme ways to reset migrations.
If you've already deleted the app it may be too late to use the migrations machinery to fix this, so you may have to go through and edit the migrations by hand. Search the migrations directories for the name of your deleted app.
Upvotes: 1