I to try run this code:
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
from blogs.models import Blog, Post
from sitename.settings import DEFAULT_CHARSET
for blog in Blog.objects.all().using('old'):
try:
Blog.objects.get(old_id=blog.id)
continue
except:
pass
new_blog = Blog(
name = blog.name,
description=blog.description,
old_id = blog.id
)
new_blog.save()
But i have exception:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
I googled this problem and find this solution:
name = blog.name.encode('ascii','ignore')
The result was upset: All Russian symbols have been removed.
"Пост номер 15-14" => "15-14"
How shall I copy the data correctly?