Reputation: 187
I have a very strange problem.
I'm trying to delete some feeds (model name: Feed) from my django model. So I run:
from rss.models import Feed
from django.db.models import Count
feeds = Feed.objects.annotate(num_subs=Count('subscriptions')).filter(num_subs=0)
for feed in feeds:
feed.delete()
And sure enough, this deletes the records from my database. In postgres, I did a query:
rs3=# select count(*) from rss_feed;
count
-------
1528
(1 row)
But then the strangest thing happens. I ran the count query again and again, and the number of feeds kept growing (without any users manually adding them), until it went back to its original number. And I've repeated this exercise a few times. How is this possible, and how do I permanently delete these records?
Upvotes: 0
Views: 108
Reputation: 77912
Databases seldom auto-populate themselves out of thin air and fresh water, so you very probably have some code somewhere that creates Feed instances (signal, cron job, whatever, doesn't even have to be python code).
Upvotes: 1
Reputation: 22697
try:
feeds = Feed.objects.annotate(num_subs=Count('subscriptions')).filter(num_subs=0).all().delete()
Upvotes: 0