sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE4\\xB

Problems:
data written to the database, the reported error

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrect string value: '\\xE4\\xB8\\xAD\\xE5\\x9B\\xBD' for column 'country_name' at row 1")

A problem I always thought it was the beginning of the field, field repeatedly confirm whether there is an error, and later found to be utf8 problem;
solution:
the establishment of a database should be set utf8 format;

create database ZYW53NCP character set utf8;

Then code modeling, as well as input data, there is no problem;
database property to UTF8;
database tables UTF8 property is also set;

Extension
1. How to view and modify database coding?

Specify the database character set when creating a database:

create  database  <数据库名>  character  set  utf8;

View Code:

> show  create  database ZYW53NCP;

Modify the database encoding format:

alter  database  <数据库> character  set  utf8;

2. How to view and modify table properties coding?
Specify the encoding format of the data table when creating the data table:

create table tb_books(
    name  varchar(45) not  null,
    price  double  not  null,
    bookCount  int  not  null,
    author  varchar(45)  not  null) default  charset = utf8;

View:

show  create  table <表名>

Modify the data encoding format table

alter  table  <表名> character  set  utf8;

Modify the field encoding format

alter  table <表名>  change  <字段名>  <字段名>  <类型>  charset  set  utf8;
alter table tb_books change name name varchar(20) character  set  utf8 not null;

Reference
View mysql database and coding

Published 73 original articles · won praise 24 · views 2556

Guess you like

Origin blog.csdn.net/weixin_44943394/article/details/104917403