【发布时间】:2020-09-28 11:24:57
【问题描述】:
我正在使用 Codeigniter 3、Ion-Auth 和 Bootstrap 4 开发一个社交网络应用程序。您可以看到 Github repo HERE .
我启用了迁移,然后创建了迁移文件002_add_messages_table.php:
class Migration_Create_Messages_Table extends CI_Migration {
public function up()
{
$this->dbforge->add_field(array(
'id'=>array(
'type'=>'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'from'=>array(
'type'=>'INT',
'constraint' => 11,
'null' => FALSE
),
'to'=>array(
'type'=>'INT',
'constraint' => 11,
'null' => FALSE
),
'message'=>array(
'type'=>'TEXT',
),
'status'=>array(
'type'=>'TINYINT',
'constraint' => 1,
),
'created_at'=>array(
'type'=>'TIMESTAMP',
'default' => NULL
),
));
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('messages');
}
public function down() {
$this->dbforge->drop_table('messages');
}
}
我还有一个Migrate.php 控制器,里面有这个内容:
<?php defined("BASEPATH") or exit("No direct script access allowed");
class Migrate extends CI_Controller{
public function index($version){
$this->load->library("migration");
if(!$this->migration->version($version)){
show_error($this->migration->error_string());
} else {
echo "Tables created";
}
}
}
当我访问http://myapp.com/index.php/migrate/index/002 时,应用程序没有创建messages 表,而是抛出以下消息:
找不到版本号为 002 的迁移。
我做错了什么?
【问题讨论】:
-
@Vickel
users表中已经存在的记录会发生什么? -
@Vickel 另外,我应该访问什么 URL?
-
@RazvanZamfir 我试过打破它,但我无法复制你的错误。它对我有用。我得到迁移 1 和 2 的工作并且迁移表得到更新。
-
@RazvanZamfir 关于您的 users 表,仅当您运行 001 迁移表时,您的组、用户、users_groups 和 login_attempts 表将被删除(它在您使用的迁移文件代码中)。否则他们会没事的。
标签: php codeigniter