'Returns a list of all table names that have associated Django models and
are in INSTALLED_APPS.
If only_existing is True, the resulting list will only include the tables
that actually exist in the database.'

def django_table_names(self, only_existing=False):

    from django.db import models, router
    tables = set()
    for app in models.get_apps():
        for model in models.get_models(app):
            if (not model._meta.managed):
                continue
            if (not router.allow_syncdb(self.connection.alias, model)):
                continue
            tables.add(model._meta.db_table)
            tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
    if only_existing:
        existing_tables = self.table_names()
        tables = [t for t in tables if (self.table_name_converter(t) in existing_tables)]
    return tables
