mysql: 插入操作错误 "data too long "

标签 mysql

在mysql中,创建一个表:

CREATE TABLE fb_group_feed (
    Post_ID varchar(64), 
    Permalink varchar(128), 
    Create_time varchar(32), 
    Updated_time varchar(32), 
    Author varchar(32),
    Author_ID bigint, 
    Message text, 
    Link varchar(1024), 
    Likes int, 
    Comments int, 
    group_ID bigint, 
    foreign key(group_ID) references fb_group_info(ID)
)

向该表插入一行数据时,出现错误:

INSERT INTO fb_group_feed VALUES (
    '1610393525875114_1842755835972214','https://www.facebook.com/groups/1610393525875114/permalink/1842755835972214/',
    '2017-01-22T17:12:41+0000','2017-01-23T00:45:16+0000','Chibura Hakkai',457297014658600,
    'Pretty hands he has... credit Wilma Alberti',
    'https://www.facebook.com/photo.php?fbid=466756323712669&set=gm.1842755835972214&type=3',   
    175,7,1610393525875114)

错误:

 Error 1406(22001): "Data too long for column 'Post_ID' at row 1")

但我已经设置了'Post_ID' varchar(64),我认为它足够长了。你能帮忙吗

最佳答案

首先您应该做的是describe fb_group_feed,它会告诉您列的当前顺序,如果您不这样做,这就是用于插入的顺序明确指定那些列。根据 doco :

If you do not specify a list of column names for INSERT ... VALUES or INSERT ... SELECT, values for every column in the table must be provided by the VALUES list or the SELECT statement. If you do not know the order of the columns in the table, use DESCRIBE tbl_name to find out.

或者(更安全)是使用显式形式:

INSERT INTO fb_group_feed (
    Post_ID, 
    Permalink,
    <other columns>
) VALUES (
    '1610393525875114_1842755835972214',
    'https://www.facebook.com/groups/blah/blah/blah/',
    <other values>
)

关于mysql: 插入操作错误 "data too long ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41797899/

相关文章:

mysql - if 和 col_length 语法

java - Mysql数据库编码问题

mysql - LOAD DATA INFILE 可以使用给定路径而不是默认的 mysql 数据路径吗?

php - 提交后下拉值未插入数据库

mysql - 备份MYSQL的应用程序

mysql - SQL 中的 CASE-WHEN-THEN-ELSE 构造

mysql - Ejabberd MySQL 模式

java - 如何从数据库中获取电子邮件和密码?我无法在 Spring security 中验证用户

mysql - Ruby on Rails 中的嵌套查询出现问题

mysql - Percona XtraDB Cluster 5.6 无法启动