Get all table names in a Django app

This will give you all of the table names, like the OP asks for:

from django.apps import apps

tables = [m._meta.db_table for c in apps.get_app_configs() for m in c.get_models()]

This will give you all model names:

from django.db import connection
tables = connection.introspection.table_names()
seen_models = connection.introspection.installed_models(tables)

This will give you all of the model names on a per app basis:

from django.apps import apps 
from django.contrib import admin 
from django.contrib.admin.sites import AlreadyRegistered 

app_models = apps.get_app_config('my_app').get_models()

Additional reading

And yet another recommends reading this answer:

Django get list of models in application

Leave a Comment