post_sync signal's created_models are incorrect with flush
|Reported by:||dcramer||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The flush command calls emit_post_sync_signal with all models, which is incorrect. This can send models as being "created" which actually don't even exist on a database.
For example, given that we have a database called foo, which does not contain django.contrib.sites, and we run the flush command, it will pass all installed models to the create_default_site method, even though Site isnt available here. With this behavior, Site then tries to create a row on this database which throws a table does not exist error.
This can be fixed by changing the flush command to match the syncdb command so that it only passes created_models which are present on this database:
e.g. (taken from syncdb)
all_models = [ (app.__name__.split('.')[-2], [m for m in models.get_models(app, include_auto_created=True) if router.allow_syncdb(db, m)]) for app in models.get_apps() ]