from django.contrib.sites.models import Site


def set_site_info(domain='datahub-local.mit.edu', name='MIT DataHub'):
    site = Site.objects.get_current()
    if site.domain != domain:
        site.domain = domain
        site.name = name
        site.save()

from django.contrib.sites.models import Site
from django.db.utils import ProgrammingError


def set_site_info(domain='datahub-local.mit.edu', name='MIT DataHub'):
    try:
        site = Site.objects.get_current()
        if site.domain != domain:
            site.domain = domain
            site.name = name
            site.save()
    except ProgrammingError:
        pass

Make sure initial migration works for new installs.
Make sure initial migration works for new installs.

Bootstrapping the Site model entirely in settings isn't great.

  from django.contrib.sites.models import Site
+ from django.db.utils import ProgrammingError
  
  
  def set_site_info(domain='datahub-local.mit.edu', name='MIT DataHub'):
+     try:
-     site = Site.objects.get_current()
+         site = Site.objects.get_current()
-     if site.domain != domain:
+         if site.domain != domain:
-         site.domain = domain
+             site.domain = domain
-         site.name = name
+             site.name = name
-         site.save()
+             site.save()
+     except ProgrammingError:
+         pass
  
Make sure initial migration works for new installs.
## Code Before:
from django.contrib.sites.models import Site


def set_site_info(domain='datahub-local.mit.edu', name='MIT DataHub'):
    site = Site.objects.get_current()
    if site.domain != domain:
        site.domain = domain
        site.name = name
        site.save()

## Instruction:
Make sure initial migration works for new installs.
## Code After:
from django.contrib.sites.models import Site
from django.db.utils import ProgrammingError


def set_site_info(domain='datahub-local.mit.edu', name='MIT DataHub'):
    try:
        site = Site.objects.get_current()
        if site.domain != domain:
            site.domain = domain
            site.name = name
            site.save()
    except ProgrammingError:
        pass
