CodeIgniter迁移:更多数据库


CodeIgniter migration: more databases

我尝试用更多的数据库进行迁移:一个默认数据库和另一个。这是database.php文件:

<?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");
}
}
?>

提前感谢您的帮助!

我找到了解决方案,如果每个人都需要帮助,我会发布它:

$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);