0

I am trying to implement CRUD in a database that will contain unicode strings. Here are the models:

from django.db import models
class Category(models.Model):
 cat_name = models.CharField(max_length=100, verbose_name="Category Name")
 def __unicode__(self):
 return self.cat_name
class Translation(models.Model):
 english_term = models.TextField(verbose_name="English Term")
 bangla_term = models.TextField(verbose_name="Bangla Term")
 bangla_variant = models.TextField(verbose_name="Variant")
 parts_of_speech = models.TextField(verbose_name="Parts of Speech")
 category = models.ForeignKey(Category, verbose_name="Category")
 def __unicode__(self):
 return self.english_term

Django by default created the database and tables with latin-swedish-ci or something. I have manually converted the database and the tables to utf8-unicode-ci (I apologize, I know I got the collation names wrong).

I have registered the models in my admin area. When I attempt to add any entries into the models, I get an error:

Warning at /admin/glossary/category/add/
Incorrect string value: '\xE0\xA6\x97\xE0\xA6\xA8...' for column 'cat_name' at row 1

Any help?

Regards

asked Mar 27, 2012 at 11:59

2 Answers 2

1

You may want to recreate DB with utf8 encoding or check configured encoding on both client and server side. Django does not create database, its your responsibility to create one and set correct parameters in Django settings for Django to connect. The only exception is sqlite3 backend, which always using utf8.

answered Mar 27, 2012 at 12:05
Sign up to request clarification or add additional context in comments.

1 Comment

Recreating the database worked. Though I manually converted the db to unicode before :s
0

Try

def __unicode__(self):
 return u'%s' % self.cat_name

in your Category model.

answered Mar 27, 2012 at 12:05

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.