as_sql in a Django Multi-DB Environment

I've had to look for this a few times in the past few days, so I figured I should post it here.

from django.db import DEFAULT_DB_ALIAS
Foo.objects.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql()

or

Foo.objects.all().query.get_compiler('default').as_sql()

Comments have been disabled for this post.