Let's say in Django I have the model:
class Test(models.Model):
name = models.CharField(max_length = 100)
I then use the following code in the Django Shell:
from app.models import Test
test = Test(name = "Hi")
test.save()
So far so good. Now I do:
Test.objects.all().delete()
I then get a very long error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\query.py", line 536, in delete
collector.collect(del_query)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\deletion.py", line 193, in collect
if self.can_fast_delete(objs):
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\deletion.py", line 155, in can_fast_delete
for related in get_candidate_relations_to_delete(opts):
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\deletion.py", line 67, in <genexpr>
f for f in candidate_model_fields
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\deletion.py", line 62, in <genexpr>
opts.get_fields(include_hidden=True) for opts in candidate_models
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\options.py", line 740, in get_fields
return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\options.py", line 802, in _get_fields
all_fields = self._relation_tree
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\utils\functional.py", line 59, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\options.py", line 709, in _relation_tree
return self._populate_directed_relation_graph()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\db\models\options.py", line 681, in _populate_directed_relation_graph
all_models = self.apps.get_models(include_auto_created=True)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\apps\registry.py", line 168, in get_models
self.check_models_ready()
File "C:\Users\Alexander\Anaconda3\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
I have seen other people get a similar error message, but they were not using the delete() operation nor were they using the Django shell. If it is relevant, I am using Django 1.8.6 in Microsoft Visual Studio 2015.