493333王中王开奖结果-王中王开奖一马中特

493333王中王开奖结果让不同类型的网络可以可靠地互相联接,王中王开奖一马中特拥有规模庞大的原创游戏,在这里您将享受的不一样快乐。

网络频道

当前位置:493333王中王开奖结果 > 网络频道 > Django框架报错“_mysql_exceptions.Warning: Incorrect str

Django框架报错“_mysql_exceptions.Warning: Incorrect str

来源:http://www.soniaLorenzana.com 作者:493333王中王开奖结果 时间:2019-09-30 17:05

在使用Django连到我的VPS上的MySQL数据库,在插入数据时,报了这样一个错误:“_mysql_exceptions.Warning: Incorrect string value: ‘xE6xB5x81xE8xA1x8C…’ for column ‘name’ at row 1”。

Model类:

我使用了中文的数据,看起来就是一个字符集不兼容的错误;Django默认使用UTF-8,而mysqld那边配置是默认使用了latin1 – default collation 。

fromdjango.dbimportmodels

解决办法如下:

fromcommon.modelsimportDepartment,User

  1. 修改 /etc/my.cnf 配置文件,然后重启mysqld。

# Create your models here.

在[client]下配置:default-character-set=utf8
在[mysqld]下配置:
default-character-set=utf8
init_connect=’SET NAMES utf8′

classEmployer(models.Model):

注意:新版MySQL(如:5.5)或MariaDB等,mysqld启动时可能会遇到“[ERROR] /usr/libexec/mysqld: unknown variable ‘default_character_set=utf8’”的错误;就应该在[mysqld]中用 character_set_server=utf8 替换掉 default_character_set=utf8 。

user = models.ForeignKey(User)

2.如果还没有解决,那么就得删掉原来建的DB,重新建并制定字符集为utf8,如:CREATE DATABASE `jay_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

birthdate = models.DateField

附我遇到的报这个错的堆栈信息:

hometown = models.CharField("籍贯",max_length=50)

 代码如下

nation = models.CharField("民族",max_length=20)

Traceback (most recent call last):
  File "/Users/jay/workspace/music-web/music/category.py", line 49, in <module>
    add(data=[{'id': 1, 'name': '流行音乐'}])
  File "/Users/jay/workspace/music-web/music/category.py", line 38, in add
    a_se.save()
  File "/Library/Python/2.7/site-packages/rest_framework/serializers.py", line 594, in save
    [self.save_object(item, **kwargs) for item in self.object]
  File "/Library/Python/2.7/site-packages/rest_framework/serializers.py", line 1041, in save_object
    obj.save(**kwargs)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 591, in save
    force_update=force_update, update_fields=update_fields)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 619, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 700, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 733, in _do_insert
    using=using, raw=raw)
  File "/Library/Python/2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 128, in execute
    return self.cursor.execute(query, args)
  File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/MySQLdb/cursors.py", line 204, in execute
    if not self._defer_warnings: self._warning_check()
  File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/MySQLdb/cursors.py", line 117, in _warning_check
    warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Incorrect string value: 'xE6xB5x81xE8xA1x8C...' for column 'name' at row 1

edu = models.TextField("教育经历",max_length=500)

resume = models.TextField("工作经历",max_length=500)

def__str__(self):

returnself.emp_name

classMeta:

verbose_name ="职工"#默认显示复数的形式

verbose_name_plural = verbose_name#显示成单数的形式

运行makemigrations正常,但运行migrate报错:

manage.py@travel > migrate"C:Program Files (x86)JetBrainsPyCharm 2016.2.3binrunnerw.exe" C:UsersAcerAppDataLocalProgramsPythonPython35python.exe "C:Program Files (x86)JetBrainsPyCharm 2016.2.3helperspycharmdjango_manage.py" migrate E:/python_project/travelOperations to perform:  Synchronize unmigrated apps: staticfiles, messages  Apply all migrations: contenttypes, common, travel_list, sessions, auth, admin, employerSynchronizing apps without migrations:  Creating tables...    Running deferred SQL...  Installing custom SQL...Running migrations:  Rendering model states... DONE  Applying employer.0003_auto_20161203_1445...Traceback (most recent call last):  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsutils.py", line 64, in execute    return self.cursor.execute(sql, params)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsmysqlbase.py", line 124, in execute    return self.cursor.execute(query, args)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlcursors.py", line 166, in execute    result = self._query(query)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlcursors.py", line 322, in _query    conn.query(q)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 835, in query    self._affected_rows = self._read_query_result(unbuffered=unbuffered)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 1019, in _read_query_result    result.read()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 1302, in read    first_packet = self.connection._read_packet()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 981, in _read_packet    packet.check_error()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 393, in check_error    err.raise_mysql_exception(self._data)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlerr.py", line 107, in raise_mysql_exception    raise errorclass(errno, errval)pymysql.err.InternalError: (1067, "Invalid default value for 'nation'")The above exception was the direct cause of the following exception:Traceback (most recent call last):  File "C:Program Files (x86)JetBrainsPyCharm 2016.2.3helperspycharmdjango_manage.py", line 41, inrun_module(manage_file, None, '__main__', True)  File "C:UsersAcerAppDataLocalProgramsPythonPython35librunpy.py", line 182, in run_module    return _run_module_code(code, init_globals, run_name, mod_spec)  File "C:UsersAcerAppDataLocalProgramsPythonPython35librunpy.py", line 96, in _run_module_code    mod_name, mod_spec, pkg_name, script_name)  File "C:UsersAcerAppDataLocalProgramsPythonPython35librunpy.py", line 85, in _run_code    exec(code, run_globals)  File "E:/python_project/travelmanage.py", line 22, inexecute_from_command_line(sys.argv)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagement__init__.py", line 354, in execute_from_command_line    utility.execute()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagement__init__.py", line 346, in execute    self.fetch_command(subcommand).run_from_argv(self.argv)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementbase.py", line 394, in run_from_argv    self.execute(*args, **cmd_options)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementbase.py", line 445, in execute    output = self.handle(*args, **options)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementcommandsmigrate.py", line 222, in handle    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsexecutor.py", line 110, in migrate    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsexecutor.py", line 148, in apply_migration    state = migration.apply(state, schema_editor)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsmigration.py", line 115, in apply    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsoperationsfields.py", line 201, in database_forwards    schema_editor.alter_field(from_model, from_field, to_field)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsbaseschema.py", line 484, in alter_field    old_db_params, new_db_params, strict)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsbaseschema.py", line 636, in _alter_field    params,  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsbaseschema.py", line 111, in execute    cursor.execute(sql, params)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsutils.py", line 79, in execute    return super(CursorDebugWrapper, self).execute(sql, params)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsutils.py", line 64, in execute    return self.cursor.execute(sql, params)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbutils.py", line 98, in __exit__    six.reraise(dj_exc_type, dj_exc_value, traceback)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangoutilssix.py", line 685, in reraise    raise value.with_traceback(tb)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsutils.py", line 64, in execute    return self.cursor.execute(sql, params)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsmysqlbase.py", line 124, in execute    return self.cursor.execute(query, args)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlcursors.py", line 166, in execute    result = self._query(query)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlcursors.py", line 322, in _query    conn.query(q)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 835, in query    self._affected_rows = self._read_query_result(unbuffered=unbuffered)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 1019, in _read_query_result    result.read()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 1302, in read    first_packet = self.connection._read_packet()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 981, in _read_packet    packet.check_error()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 393, in check_error    err.raise_mysql_exception(self._data)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlerr.py", line 107, in raise_mysql_exception    raise errorclass(errno, errval)django.db.utils.InternalError: (1067, "Invalid default value for 'nation'")Process finished with exit code 1manage.py@travel > makemigrations"C:Program Files (x86)JetBrainsPyCharm 2016.2.3binrunnerw.exe" C:UsersAcerAppDataLocalProgramsPythonPython35python.exe "C:Program Files (x86)JetBrainsPyCharm 2016.2.3helperspycharmdjango_manage.py" makemigrations E:/python_project/travelMigrations for 'employer':  0005_auto_20161203_1451.py:    - Change Meta options on employerProcess finished with exit code 0manage.py@travel > migrate"C:Program Files (x86)JetBrainsPyCharm 2016.2.3binrunnerw.exe" C:UsersAcerAppDataLocalProgramsPythonPython35python.exe "C:Program Files (x86)JetBrainsPyCharm 2016.2.3helperspycharmdjango_manage.py" migrate E:/python_project/travelOperations to perform:  Synchronize unmigrated apps: messages, staticfiles  Apply all migrations: employer, auth, travel_list, admin, sessions, common, contenttypesSynchronizing apps without migrations:  Creating tables...    Running deferred SQL...  Installing custom SQL...Running migrations:  Rendering model states... DONE  Applying employer.0003_auto_20161203_1445...Traceback (most recent call last):  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsutils.py", line 64, in execute    return self.cursor.execute(sql, params)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsmysqlbase.py", line 124, in execute    return self.cursor.execute(query, args)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlcursors.py", line 166, in execute    result = self._query(query)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlcursors.py", line 322, in _query    conn.query(q)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 835, in query    self._affected_rows = self._read_query_result(unbuffered=unbuffered)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 1019, in _read_query_result    result.read()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 1302, in read    first_packet = self.connection._read_packet()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 981, in _read_packet    packet.check_error()  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlconnections.py", line 393, in check_error    err.raise_mysql_exception(self._data)  File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagespymysqlerr.py", line 107, in raise_mysql_exception    raise errorclass(errno, errval)pymysql.err.InternalError: (1067, "Invalid default value for 'nation'")The above exception was the direct cause of the following exception:Traceback (most recent call last):  File "C:Program Files (x86)JetBrainsPyCharm 2016.2.3helperspycharmdjango_manage.py", line 41, inrun_module(manage_file, None, '__main__', True)  File "C:UsersAcerAppDataLocalProgramsPythonPython35librunpy.py", line 182, in run_module    return _run_module_code(code, init_globals, run_name, mod_spec)  File "C:UsersAcerAppDataLocalProgramsPythonPython35librunpy.py", line 96, in _run_module_code    mod_name, mod_spec, pkg_name, script_name)  File "C:UsersAcerAppDataLocalProgramsPythonPython35librunpy.py", line 85, in _run_code    exec(code, run_globals)  File "E:/python_project/travelmanage.py", line 22, inexecute_from_command_line(sys.argv)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagement__init__.py", line 354, in execute_from_command_line

utility.execute()

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagement__init__.py", line 346, in execute

self.fetch_command(subcommand).run_from_argv(self.argv)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementbase.py", line 394, in run_from_argv

self.execute(*args, **cmd_options)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementbase.py", line 445, in execute

output = self.handle(*args, **options)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangocoremanagementcommandsmigrate.py", line 222, in handle

executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsexecutor.py", line 110, in migrate

self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsexecutor.py", line 148, in apply_migration

state = migration.apply(state, schema_editor)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsmigration.py", line 115, in apply

operation.database_forwards(self.app_label, schema_editor, old_state, project_state)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbmigrationsoperationsfields.py", line 201, in database_forwards

schema_editor.alter_field(from_model, from_field, to_field)

File "C:UsersAcerAppDataLocalProgramsPythonPython35libsite-packagesdjangodbbackendsbaseschema.py", line 484, in alter_field

本文由493333王中王开奖结果发布于网络频道,转载请注明出处:Django框架报错“_mysql_exceptions.Warning: Incorrect str

关键词:

上一篇:没有了

下一篇:没有了