Update migration.py for python3

Make migrations compatible with python3