2012-11-30 31 views
1

任何幫助都會很棒。Drupal 7 hook_schema沒有安裝數據庫表

function request_gold_pack_schema() { 
    $schema['request_gold_pack_customer_details'] = array(
     'description' => 'Table to store all customer details.', 
     'fields' => array(  
      'rid' => array(
       'type' => 'int', 
       'not null' => TRUE, 
       'default' => 0, 
       'auto increment' => TRUE 
      ), 
      'title' => array(
       'type' => 'varchar', 
       'length' => 10, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'first_name' => array(
       'type' => 'varchar', 
       'length' => 50, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'last_name' => array(
       'type' => 'varchar', 
       'length' => 50, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'house_name_no' => array(
       'type' => 'varchar', 
       'length' => 50, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'street' => array(
       'type' => 'varchar', 
       'length' => 160, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'town' => array(
       'type' => 'varchar', 
       'length' => 50, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'county' => array(
       'type' => 'varchar', 
       'length' => 50, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'telephone' => array(
       'type' => 'int', 
       'length' => 12, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'email' => array(
       'type' => 'varchar', 
       'length' => 255, 
       'not null' => TRUE, 
       'default' => '' 
      ), 
      'date_registered' => array(
       'mysql_type' => 'DATETIME', 
       'not null' => TRUE 
      ), 
      'primary' => array(
       'rid' 
      ) 
     ) 
    ); 

    return $schema; 
} 

這使我以下錯誤

說明:未定義指數:輸入DatabaseSchema_mysql-> processField()(/Users/richardskinner/Sites/www.goldrushmoney.com-local的205線/httpdocs/includes/database/mysql/schema.inc)。 注意:在DatabaseSchema_mysql-> processField()(/Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/mysql/schema.inc)的第205行中未定義索引::正常。 PDOException:SQLSTATE [42000]:語法錯誤或訪問衝突:1064您的SQL語法中有錯誤;檢查與您的MySQL服務器版本對應的手冊,以在DEFAULT NULL附近使用正確的語法ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT'Table to stor'at line 13:CREATE TABLE {request_gold_pack_customer_details}(rid INT NOT NULL DEFAULT 0 ,title VARCHAR(10)NOT NULL DEFAULT'',first_name VARCHAR(50)NOT NULL DEFAULT'',last_name VARCHAR(50)NOT NULL DEFAULT'',house_name_no VARCHAR(50)NOT NULL DEFAULT'',street VARCHAR(160) NOT NULL DEFAULT'',town VARCHAR(50)NOT NULL DEFAULT'',county VARCHAR(50)NOT NULL DEFAULT'',telephone INT NOT NULL DEFAULT'',email VARCHAR(255)NOT NULL DEFAULT'',date_registered DATETIME NOT NULL,primary DEFAULT NULL)ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT'Table to store all custome詳細信息。'; db_create_table()中的Array()(/Users/richardskinner/Sites/www.goldrushmoney.com-local/httpdocs/includes/database/database.inc的第2688行)。

一直試圖找到一個小時的解決方案。

謝謝。

回答

2

這是您的主鍵問題。你的hve的田野數組中列出(它不應該),它應該作爲「主鍵」,而不是「主要」被引用,就像這樣:

function request_gold_pack_schema(){ 
    $schema['request_gold_pack_customer_details'] = array(
     'description' => 'Table to store all customer details.', 
     'fields' => array(  
       // Your field definitions 
     ), 
     'primary key' => array(
      'rid' 
     ) 
    ); 
    return $schema; 
} 

檢查出drupal.org的schema api documentation

我還建議設置rid字段鍵入serial並且放棄自動增量參數(Drupal將處理該參數)。所以,「擺脫」字段的定義是這樣:

'rid' => array(
    'type' => 'serial', 
    'unsigned' => TRUE, 
    'not null' => TRUE, 
) 
+2

輝煌,你是一個真正的紳士。完美地工作。謝謝。 –

+1

實際上,在您給出的鏈接的{node}示例中,主鍵是'fields'下列出的第一個鍵。這與我目前正在處理的示例模塊中的entity_example一樣。也許這只是主要/主要問題?我可能是錯的 - 我還沒有得到我的工作。 –

0

你必須在類型「詮釋」的Drupal 7指定大小...即

'rid' => array(
'type' => 'int', 
'not null' => TRUE, 
'size' => 'normal', 
'auto increment' => TRUE, 
), 

大小可正常,小,大 檢查Drupal 7數據類型。