I want to run the code below in a file called migration.py

from django.db import connections
from django.core.exceptions import ObjectDoesNotExist
from django.db.utils import ConnectionDoesNotExist
from django.conf import settings
import models

def setup_cursor():
    try:
        cursor = connections['legacy'].cursor()
    except ConnectionDoesNotExist:
        print "Legacy database is not configured"
        return None


def import_products():
    cursor = setup_cursor()
    if cursor is None:
        return
        ## it's important selecting the id field, so that we can keep the 
publisher - book relationship
    sql = """SELECT * FROM shopinventory"""
    cursor.execute(sql)
    for row in cursor.fetchall():
        p = models.Product.objects.get(sku=row['Item'])
        if p:
            p.meta_keywords = row['Item_description']
            p.save()


def main():
    import_products()


if __name__=="__main__":
    main()

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to