是什么导致 Codeigniter 3 中出现此 "No migration could be found with the version number" 错误?
What causes this "No migration could be found with the version number" error in Codeigniter 3?
我正在使用 Codeigniter 3 开发 社交网络 应用程序,Ion-Auth and Bootstrap 4. You can see the 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
table,而是抛出消息:
No migration could be found with the version number: 002.
我做错了什么?
*** 已更新 ***
首先,编辑 application/config/migration.php 并设置
$config['migration_type'] = 'sequential'; // was 'timestamp' in your repo
其次,编辑您的迁移文件并将 class 名称更改为
class Migration_Add_Messages_Table extends CI_Migration {
或将文件重命名为 002_create_messages_table
(class名称和文件名需要相似)
然后
如以下查询
SELECT version FROM migrations
返回任何大于或等于 2 的值,您可以做的是降低迁移 table 和 re-run 迁移中的版本值(如果它不是自动的)。
我正在使用 Codeigniter 3 开发 社交网络 应用程序,Ion-Auth and Bootstrap 4. You can see the 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
table,而是抛出消息:
No migration could be found with the version number: 002.
我做错了什么?
*** 已更新 ***
首先,编辑 application/config/migration.php 并设置
$config['migration_type'] = 'sequential'; // was 'timestamp' in your repo
其次,编辑您的迁移文件并将 class 名称更改为
class Migration_Add_Messages_Table extends CI_Migration {
或将文件重命名为 002_create_messages_table (class名称和文件名需要相似)
然后 如以下查询
SELECT version FROM migrations
返回任何大于或等于 2 的值,您可以做的是降低迁移 table 和 re-run 迁移中的版本值(如果它不是自动的)。