代码之家  ›  专栏  ›  技术社区  ›  luc

加载夹具时django unittest出错

  •  4
  • luc  · 技术社区  · 15 年前

    1. 对于用户和它的工作正常。
    2. 对于某些网页

    夹具2导致以下错误:

    Problem installing fixture 'C:\Users\luc\Dev\Hg\mnl-adminpub\website\fixtures\website-unittest.json': Traceback (most recent call last):
      File "C:\Python26\lib\site-packages\django\core\management\commands\loaddata.py", line 169, in handle
        obj.save(using=using)
      File "C:\Python26\lib\site-packages\django\core\serializers\base.py", line 165, in save
        models.Model.save_base(self.object, using=using, raw=True)
      File "C:\Python26\lib\site-packages\django\db\models\base.py", line 528, in save_base
        result = manager._insert(values, return_id=update_pk, using=using)
      File "C:\Python26\lib\site-packages\django\db\models\manager.py", line 195, in _insert
        return insert_query(self.model, values, **kwargs)
      File "C:\Python26\lib\site-packages\django\db\models\query.py", line 1479, in insert_query
        return query.get_compiler(using=using).execute_sql(return_id)
      File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 783, in execute_sql
        cursor = super(SQLInsertCompiler, self).execute_sql(None)
      File "C:\Python26\lib\site-packages\django\db\models\sql\compiler.py", line 727, in execute_sql
        cursor.execute(sql, params)
      File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 86, in execute
        return self.cursor.execute(query, args)
      File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 173, in execute
        self.errorhandler(self, exc, value)
      File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
        raise errorclass, errorvalue
    OperationalError: (1366, "Incorrect string value: '\\xE2\\x80\\xA8<br...' for column 'html' at row 1")
    

    3 回复  |  直到 15 年前
        1
  •  9
  •   Xiong Chiamiov    13 年前

    你应该使用 TEST_CHARSET ,但是

    DATABASES = {
          'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'test_sbet',                      
            'USER': 'test_sbet',                      
            'TEST_CHARSET': 'UTF8',
        }
    }
    
        2
  •  1
  •   Ofri Raviv    15 年前

    如果这只发生在测试过程中,我会怀疑一些测试设置,比如 TEST_CHARSET

    TEST_DATABASE_CHARSET .

        3
  •  1
  •   Kirill Zinovjev    9 年前

    有同样的问题。使用 utfmb4 在MySql数据库中添加 CHARSET 关键在于 TEST

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'OPTIONS': {
                ...
                'charset': 'utf8mb4',
            },
            'TEST': {'CHARSET': 'utf8mb4',},
        }
    }
    
    推荐文章