Skip to content

Instantly share code, notes, and snippets.

@jmorenoamor
Created February 2, 2018 10:01
Show Gist options
  • Save jmorenoamor/886915956136734c554c35c02ba0faf1 to your computer and use it in GitHub Desktop.
Save jmorenoamor/886915956136734c554c35c02ba0faf1 to your computer and use it in GitHub Desktop.
Create superuser in migration
from __future__ import unicode_literals
from django.db import models, migrations
from django.contrib.auth.models import User
def create_superuser(apps, schema_editor):
User.objects.create_superuser('admin', '[email protected]', 'admin')
def delete_superuser(apps, schema_editor):
User.objects.get(username="admin").delete()
class Migration(migrations.Migration):
dependencies = [
('diet', '0001_initial'),
]
operations = [
migrations.RunPython(create_superuser, delete_superuser),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment