Skip to content

Instantly share code, notes, and snippets.

@marcusshepp
Created March 11, 2016 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusshepp/528c4fdb22d0c0a4c880 to your computer and use it in GitHub Desktop.
Save marcusshepp/528c4fdb22d0c0a4c880 to your computer and use it in GitHub Desktop.
How to create a function inside a Django migration file
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-11 23:37
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
def foo(apps, schema_editor):
FooBar = apps.get_model("bar", "FooBar")
fb = FooBar(name="foo and bar")
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='FooBar',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
],
),
migrations.RunPython(foo),
]
@marcusshepp
Copy link
Author

Indentation might be bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment