Murthy Sandeep
unread,Mar 22, 2015, 5:30:34 AM3/22/15Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com, con...@arkade.info
Hi
I have created an data migration script for populating one of
app db tables with data from a JSON file. First I ran
python manage.py makemigrations --empty TPP_App
(‘TPP_App’ is the name of my app) and then I added a custom
method called populate_db which will use bulk_create to add
multiple entries to the table, and then do a save() to write the
changes to the db. At the moment the custom method is empty
because I am still working on it, but the script looks like this right
now
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
def populate_db( apps, schema_editor ):
print ‘Populating db from JSON file...'
class Migration(migrations.Migration):
dependencies = [
('TPP_App', '0003_auto_20150224_2024'),
]
operations = [
migrations.RunPython( populate_db ),
]
How do I test this script to make sure the custom method works
as expected, before I run it fully? Can I call this from the interpreter
and test it with the db API?
At the moment if I do
python manage.py migrate
it reports there are no migrations to apply.
Sandeep