Data migration script populating db table - testing

26 views
Skip to first unread message

Murthy Sandeep

unread,
Mar 22, 2015, 5:30:34 AM3/22/15
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


signature.asc

Filipe Ximenes

unread,
Mar 23, 2015, 9:19:45 AM3/23/15
to django...@googlegroups.com, con...@arkade.info
One way to do it is to run all operations, don't call "save" and verify "manually" if objects are correct.
I don't know about other methods, but if someone else does it would be great.


Sandeep


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/10767D81-937A-4F08-983A-B055C4AB3982%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.



--
  
Filipe Ximenes
+55 (81) 8245-9204
Vinta Software Studio
http://www.vinta.com.br
Reply all
Reply to author
Forward
0 new messages