简体   繁体   中英

django admin crashes when trying to update record but not when inserting a new one

I'm having a weird problem:

technical info for developemnt (production will be on linux/apache/Mysql) macosx 2.6.6 python 2.6.1 django 1.3 mysql 5.1 and MySQLdb to connect the python to the MySQL...

I'm new at django as every one can see from past questions...but need to get really strong at it, really fast...the problem is that it is really not that smooth for me...

OK, for the question. I'm doing the django tutorial (not for fun, i need to learn it really fast because i need to develop a huge system with it).

I did all the the tutorial untill now and at the stage where i added the admin.

When i try to edit the poll record (if any one know the django 1.3 tutrial) the site crashes with the following exception:

Warning at /admin/polls/poll/2/ Incorrect string value: '\\xD7\\xA9\\xD7\\x95\\xD7\\xA0...' for column 'change_message' at row 1

there is not problem with adding a new record to the same table, just to edit one....

if any one know's any thing about it....

# Create your models here.

class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published')

def __unicode__(self):
    return self.question

def was_published_today(self):
    return self.pub_date.date() == datetime.date.today()

This is the model, and another this i saw, my MySQL DB is latin1 and not UTF-8...python is unicode....maybe that is the problem....

But still, i can't figure out why i can add records but can't edit them....isn't that the weird part?

I was experiencing same issue but using Django 1.4. I used the recommendation of photoionized but adapted to this version (where auth_message is gone, but you can find change_message in django_admin_log ). So:

ALTER TABLE django_admin_log CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

Sounds like a database character set issue. Can you check the default character set of auth_message table in your database?

If your table can't handle utf8 it would throw this error.

Open your mysql shell and run the following:

mysql> show variables like  'character\_set\_%';

Are there any utf8 values from above?

Assuming it's a mysql issue, swap out your db settings to sqlite3:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'database.sqlite3',           
        'USER': '',                      
        'PASSWORD': '',                  
        'HOST': '',                     
        'PORT': '',                   
    }
}

Sync and try to input some data again.

Find the Column 'change_message' in the Table 'django_admin_log'. Change the character set to utf-8 default. Done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM