2012-09-26 14 views
0

我使用下面的代碼通過添加額外的列來修改數據庫表:Drupal的加場VARCHAR發出

$componentName = 'is_this_the_first_time_you_have_taken_part_in_or_attended_this_event'; 
    db_add_field('webform_views_data', 
     $componentName, 
      array('type' => 'varchar', 'length' => 255, 'not null' => TRUE) 
    ); 

不過,我不斷收到以下錯誤:

> PDOException: SQLSTATE[42000]: Syntax error or access violation: 1059 
> Identifier name 
> 'is_this_the_first_time_you_have_taken_part_in_or_attended_this_event' 
> is too long: ALTER TABLE {webform_views_data} ADD 
> `is_this_the_first_time_you_have_taken_part_in_or_attended_this_event` 
> VARCHAR(255) NULL DEFAULT NULL; Array () in db_add_field() (line 2812 
> of /var/www/mysite/includes/database/database.inc). 

關於明顯我想我們都可以同意'is_this_the_first_time_you_have_taken_part_in_or_attended_this_event'不是255個字符長。

不知道是什麼問題...幫助將不勝感激。

回答

1

VARCHAR(255)或255個字符是字段的內容最大字符,但錯誤指出字段的名稱太長。

也就是說,is_this_the_first_time_you_have_taken_part_in_or_attended_this_event對於字段名稱來說太長。

有關相關問題,請參閱this answer,並注意您的字段名稱的字符限制是根據MySQL documentation的64個字符。