2016-07-25 137 views
0

我試圖做更多的數據庫遷移:一個默認數據庫和另一個。 這是database.php中的文件:CodeIgniter遷移:更多的數據庫

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

$active_group = 'default'; 
$query_builder = TRUE; 

$db['default'] = array(
'dsn' => '', 
'hostname' => '127.0.0.1', 
'username' => 'root', 
'password' => '', 
'database' => 'buy_prova_test', 
'dbdriver' => 'mysqli', 
'dbprefix' => 'ext_', 
'pconnect' => FALSE, 
//'db_debug' => FALSE, 
'db_debug' => (ENVIRONMENT !== 'production'), 
'cache_on' => FALSE, 
'cachedir' => '', 
'char_set' => 'utf8', 
'dbcollat' => 'utf8_general_ci', 
'swap_pre' => '', 
'encrypt' => FALSE, 
'compress' => FALSE, 
'stricton' => FALSE, 
'failover' => array(), 
'save_queries' => TRUE 
); 

$db['oauth_test'] = array(
'dsn' => '', 
'hostname' => '127.0.0.1', 
'username' => 'root', 
'password' => '', 
'database' => 'oauth_test', 
'dbdriver' => 'mysqli', 
'dbprefix' => '', 
'pconnect' => FALSE, 
//'db_debug' => FALSE, 
'db_debug' => (ENVIRONMENT !== 'production'), 
'cache_on' => FALSE, 
'cachedir' => '', 
'char_set' => 'utf8', 
'dbcollat' => 'utf8_general_ci', 
'swap_pre' => '', 
'encrypt' => FALSE, 
'compress' => FALSE, 
'stricton' => FALSE, 
'failover' => array(), 
'save_queries' => TRUE 
); 

?> 

這一點,相反,第一遷移運行正常:

<?php 
class Migration_Create_external_site_manager extends CI_Migration 
{ 
public function up() 
{ 
    $this->dbforge->add_field(" 
    ID bigint(20) NOT NULL AUTO_INCREMENT, 
    sito varchar(255) NOT NULL, 
    url_override text NOT NULL, 
    title varchar(255) NOT NULL, 
    title_facebook text NOT NULL, 
    description text NOT NULL, 
    description_facebook text NOT NULL, 
    description_twitter text NOT NULL, 
    img_facebook text NOT NULL, 
    img_twitter text NOT NULL, 
    PRIMARY KEY (ID)" 
    ); 
    $this->dbforge->create_table('external_site_manager'); 
} 

public function down() 
{ 
    $this->dbforge->drop_table('external_site_manager'); 
} 
} 
?> 

而且這是我會做oauth_test數據庫中的第二個遷移,它不返回錯誤,但我沒有看到數據庫中的任何表格:

<?php 
class Migration_Create_oauth_test extends CI_Migration 
{ 


public function up() 
{ 
    $oauth=$this->load->database('oauth_test',true); 
    $this->oauth_forge=$this->load->dbforge($oauth,TRUE)); 
    $this->oauth_forge->add_field(" 
     access_token varchar(40) NOT NULL, 
     client_id varchar(80) NOT NULL, 
     user_id varchar(255) DEFAULT NULL, 
     expires timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
     scope varchar(2000) DEFAULT NULL, 
     PRIMARY KEY (access_token)"); 
    $this->oauth_forge->create_table("oauth_access_tokens"); 
    $this->oauth_forge->add_field(" 
     client_id varchar(80) NOT NULL, 
     client_secret varchar(80) NOT NULL, 
     redirect_uri varchar(2000) NOT NULL, 
     grant_types varchar(80) DEFAULT NULL, 
     scope varchar(100) DEFAULT NULL, 
     user_id varchar(80) DEFAULT NULL, 
     PRIMARY KEY (client_id) 
     "); 
    $this->oauth_forge->create_table("oauth_clients"); 
} 

public function down() 
{ 
    $oauth=$this->load->database('oauth_test',true); 
    $this->oauth_forge=$this->load->dbforge($oauth,TRUE)); 
    $this->oauth_forge->drop_table("oauth_clients"); 
    $this->oauth_forge->drop_table("oauth_access_tokens"); 
} 
} 

?> 

在此先感謝您的幫助!

回答

0

,我發現自己的解決方案,如果每個人都需要幫助,我將它張貼:

$this->db->close(); /*close connection to default*/ 
$this->db = $this->load->database('oauth_test',true);/*switch to oauth_test*/ 
$this->myforge=$this->load->dbforge($this->db, TRUE);