Renaming, Django's Default Site

Published 26 May, 2020; last updated on 2 December, 2020.

When you make use of Django’s sites framework, it’ll create a default site named “”.

This default site will pop up in a few places, and I often see it when making use of django-allauth. Out of the box, password reset emails will be sent with the subject “[] Password Reset E-mail”, start with “Hello from!”, and will go on to mention a couple more times.

Of course you can just rename this default site in admin, but I’m forgetful and want to avoid product launches inviting users to check out “”.

To rename the site you’ll need a data migration, but it’s a little tricky to get this right.

The default “” site already exists if you’ve already run migrations, but it won’t exist if you’re running migrations to create a new app (the default site is created in a post-migration hook).

Thankfully, the code which creates the default site is clever enough to check if a site was already created during migrations. So we just need to get in before it tries to be helpful.

After running a few tests, this was the data migration I came up with:

from django.db import migrations

def setup_default_site(apps, schema_editor):
    Set up or rename the default site created by Django.
    Site = apps.get_model("sites", "Site")

    name = "My Cool Site"
    domain = ""

        site = Site.objects.get(domain="") = name
        site.domain = domain

    except Site.DoesNotExist:
        # No site with domain exists.
        # Create a default site, but only if no sites exist.
        if Site.objects.count() == 0:
            Site.objects.create(name=name, domain=domain)

class Migration(migrations.Migration):

    dependencies = [
        ("my_cool_site", "0001_initial"),
        ("sites", "0002_alter_domain_unique"),

    operations = [
        migrations.RunPython(setup_default_site, migrations.RunPython.noop),