2013-07-12 118 views
-1

使用cakephp-elasticsearch插件來索引和搜索mysql Db。我跟着從這個鏈接教程:錯誤:SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'details.id'

https://github.com/dkullmann/CakePHP-Elastic-Search-DataSource 

我所創建的「詳細信息」模塊:

<?php 
class details extends AppModel { 

    public $useDbConfig = 'index'; 
public $useType = 'details'; 

    public $_mapping = array(
     'name' => array('type' => 'string'), 
     'addr' => array('type' => 'string'), 
     'phno' => array('type' => 'string'), 
     'city' => array('type' => 'string'), 
     'state' => array('type' => 'string'), 

    ); 

    public function elasticMapping() { 
     return $this->_mapping; 
    } 
} 
?> 

開始索引記錄我使用這個命令:

Console/cake Elastic.elastic index details 

即時得到的以下錯誤:

Retrieving data from mysql starting on 1970-01-01 00:00:00 
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'details.id' in 'field list' 
#0 /var/www/cakephp/lib/Cake/Model/Datasource/DboSource.php(460): PDOStatement->execute(Array) 
#1 /var/www/cakephp/lib/Cake/Model/Datasource/DboSource.php(426): DboSource->_execute('SELECT `details...', Array) 
#2 /var/www/cakephp/lib/Cake/Model/Datasource/DboSource.php(669): DboSource->execute('SELECT `details...', Array, Array) 
#3 /var/www/cakephp/lib/Cake/Model/Datasource/DboSource.php(1080): DboSource->fetchAll('SELECT `details...', false) 
#4 /var/www/cakephp/lib/Cake/Model/Model.php(2696): DboSource->read(Object(details), Array) 
#5 /var/www/cakephp/app/Plugin/Elastic/Console/Command/ElasticShell.php(288): Model->find('all', Array) 
#6 /var/www/cakephp/lib/Cake/Console/Shell.php(389): ElasticShell->index() 
#7 /var/www/cakephp/lib/Cake/Console/ShellDispatcher.php(200): Shell->runCommand('index', Array) 
#8 /var/www/cakephp/lib/Cake/Console/ShellDispatcher.php(68): ShellDispatcher->dispatch() 
#9 /var/www/cakephp/app/Console/cake.php(37): ShellDispatcher::run(Array) 
#10 {main} 

我沒有任何名爲id的字段..我會做什麼錯誤?請幫幫我!!

回答

1

所有的數據庫表都需要一個主鍵

,默認情況下,該字段的名稱是id。如果表有不同的主鍵,它需要設置primaryKey屬性,使蛋糕知道它是什麼:

class MyModel extends AppModel { 

    $primaryKey = 'odd'; 

} 

是常規

What mistake i would have done?

有代碼對方失誤的問題,即:

型號名稱是單數

所以,class details - >class detail

當查找要使用的表時,Cake會自動使用複數形式(details)。

類名是CameBacked

所以class detail - >class Detail

有書中更多有關CakePHP's conventions

這也隱含文檔中增強了ES plugin,比較問題的CLI調用:

Console/cake Elastic.elastic index details 
           ^lower case plural model name 

與一個在ES插件自述:

Console/cake Elastic.elastic index Contact 
           ^Correct case and singular 

不遵守約定是一種查找不一致行爲的簡單方法。

+0

非常感謝。我根據您的指示進行了更改。但是當我運行這個命令控制檯/蛋糕Elastic.elastic索引詳細信息我得到以下錯誤:錯誤:SQLSTATE [42S22]:未找到列:1054未知列'在'子句中'Detail.modified' –

+0

'默認情況下IndexableBehavior將聲明您的「修改」字段作爲跟蹤何時更新或創建每條記錄以便與ElasticSearch同步的字段。「我建議閱讀自述文件;)。祝你好運。 – AD7six

相關問題