from __future__ import unicode_literals

from django.db import migrations, models


def forwards(apps, schema_editor):
    """Create Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    Group.objects.create(name='Onboarding')


def backwards(apps, schema_editor):
    """Delete Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    Group.objects.filter(name='Onboarding').delete()


class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0010_auto_20171221_0112'),
    ]

    operations = [
        migrations.RunPython(forwards, backwards)
    ]

from __future__ import unicode_literals

from django.db import migrations, models


def forwards(apps, schema_editor):
    """Create Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    if not Group.objects.filter(name='Onboarding').exists():
        Group.objects.create(name='Onboarding')


def backwards(apps, schema_editor):
    """Delete Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    if Group.objects.filter(name='Onboarding').exists():
        Group.objects.filter(name='Onboarding').delete()


class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0010_auto_20171221_0112'),
    ]

    operations = [
        migrations.RunPython(forwards, backwards)
    ]

Check if Onboarding exists before creating.
Check if Onboarding exists before creating.

  from __future__ import unicode_literals
  
  from django.db import migrations, models
  
  
  def forwards(apps, schema_editor):
      """Create Onboarding group."""
      Group = apps.get_model('auth', 'Group')
+     if not Group.objects.filter(name='Onboarding').exists():
-     Group.objects.create(name='Onboarding')
+         Group.objects.create(name='Onboarding')
  
  
  def backwards(apps, schema_editor):
      """Delete Onboarding group."""
      Group = apps.get_model('auth', 'Group')
+     if Group.objects.filter(name='Onboarding').exists():
-     Group.objects.filter(name='Onboarding').delete()
+         Group.objects.filter(name='Onboarding').delete()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('profiles', '0010_auto_20171221_0112'),
      ]
  
      operations = [
          migrations.RunPython(forwards, backwards)
      ]
  
Check if Onboarding exists before creating.
## Code Before:
from __future__ import unicode_literals

from django.db import migrations, models


def forwards(apps, schema_editor):
    """Create Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    Group.objects.create(name='Onboarding')


def backwards(apps, schema_editor):
    """Delete Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    Group.objects.filter(name='Onboarding').delete()


class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0010_auto_20171221_0112'),
    ]

    operations = [
        migrations.RunPython(forwards, backwards)
    ]

## Instruction:
Check if Onboarding exists before creating.
## Code After:
from __future__ import unicode_literals

from django.db import migrations, models


def forwards(apps, schema_editor):
    """Create Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    if not Group.objects.filter(name='Onboarding').exists():
        Group.objects.create(name='Onboarding')


def backwards(apps, schema_editor):
    """Delete Onboarding group."""
    Group = apps.get_model('auth', 'Group')
    if Group.objects.filter(name='Onboarding').exists():
        Group.objects.filter(name='Onboarding').delete()


class Migration(migrations.Migration):

    dependencies = [
        ('profiles', '0010_auto_20171221_0112'),
    ]

    operations = [
        migrations.RunPython(forwards, backwards)
    ]
