2017-01-23 55 views
0

,創建一個表:的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),我認爲這是很長enough.Could請您爲

幫助
+2

我不能重現該問題:HTTP://www.sqlfiddle。 com /#!9/345eb你確定列的順序是你顯示的嗎? – Barmar

回答

0

第一個你應該做的事情是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> 
) 
+0

他展示了使用的「CREATE TABLE」查詢。這些列始終與此處指定的順序相同。 – Barmar

+1

@Barmar,創建後很可能會對錶格進行更改,或者語句可能錯誤/被誤解,或者當舊錶格仍舊存在時可能無法創建新表格(可能少於所需空間) 。底線是似乎插入的數據應該符合MySQL的抱怨。我的建議仍然存在,'describe table'是確定「裸體」插入將執行什麼操作的最終方式,並且您不應該使用裸插入,以實現便攜性。 – paxdiablo