【问题标题】:migration not working in codeigniter迁移在 codeigniter 中不起作用
【发布时间】:2014-10-12 17:51:40
【问题描述】:

我有一个问题,我的迁移不起作用,添加到数据库的版本为 0,但我为版本配置了 1,它没有运行我的创建表方法

class Migration_Add_blog extends CI_Migration {

    public function up()
    {
        $this->dbforge->add_field(array(
            'blog_id' => array(
                'type' => 'INT',
                'constraint' => 5,
                'unsigned' => TRUE,
                'auto_increment' => TRUE
            ),
            'blog_title' => array(
                'type' => 'VARCHAR',
                'constraint' => '100',
            ),
            'blog_description' => array(
                'type' => 'TEXT',
                'constraint'=> '100'
            ),
        ));

        $this->dbforge->create_table('blog');
        $this->dbforge->add_key('id',TRUE);
    }

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

【问题讨论】:

    标签: php mysql database codeigniter frameworks


    【解决方案1】:

    在我的情况下,我的架构版本已经完成,因此创建表将无法正常工作,因此您必须回滚您的架构:

    $this->migration->version($old_schema);
    

    如果回滚有错误,请尝试在您的方法 down() 中添加注释,因为该表还不存在。

    成功回滚后,现在再次尝试迁移。

    【讨论】:

      【解决方案2】:

      您确定文件命名正确吗?

      version_fileName.php

      在你的前任。

       001_Migration_Add_blog.php

      $this->dbforge->create_table('blog');
      $this->dbforge->add_key('id',TRUE);
      

      $this->dbforge->add_key('id',TRUE);
      $this->dbforge->create_table('blog');
      

      更新架构

      $this->load->library('migration');
      
      if ( ! $this->migration->current())
      {
          show_error($this->migration->error_string());
      }
      

      $this->load->library('migration');
      
       if ( ! $this->migration->version(5); // or 6 , 7 your migration version
        {
         show_error($this->migration->error_string());
         }
      

      【讨论】:

        猜你喜欢
        • 2018-04-03
        • 2023-03-14
        • 2012-09-08
        • 2020-10-25
        • 2017-06-18
        • 1970-01-01
        相关资源
        最近更新 更多