【发布时间】:2018-11-10 07:22:42
【问题描述】:
现在我正在尝试使用迁移到我的 Codeigniter 项目。
我在application/migrations 和Migrate.php 上创建了一些迁移文件,作为控制器在我尝试迁移表时创建表。
我将给出迁移文件的示例以及此线程的 Migrate.php 中的内容。
问题发生在我运行迁移时,我使用 cli php index.php migrate current 运行。它显示migration success,但只有migrations 创建的表。有人跟我有同样的问题吗?
Migrate.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Migrate extends CI_Controller {
function __construct()
{
parent::__construct();
if(! $this->input->is_cli_request()) {
show_404();
exit;
}
$this->load->library('migration');
}
function current()
{
if ($this->migration->current()) {
log_message('error', 'Migration Success.');
echo "Migration Success";
} else {
log_message('error', $this->migration->error_string());
echo $this->migration->error_string();
}
}
function rollback($version)
{
if ($this->migration->version($version)) {
log_message('error', 'Migration Success.');
echo "Migration Success";
} else {
log_message('error', $this->migration->error_string());
echo $this->migration->error_string();
}
}
function latest()
{
if ($this->migration->latest()) {
log_message('error', 'Migration Success.');
echo "Migration Success";
} else {
log_message('error', $this->migration->error_string());
echo $this->migration->error_string();
}
}
}
迁移文件示例。
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Add_Facility_Types extends CI_Migration {
public function up()
{
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('facility_types');
}
public function down()
{
$this->dbforge->drop_table('facility_types');
}
}
【问题讨论】:
标签: php database codeigniter migration