CodeIgniter-错误编号:1146


CodeIgniter - Error Number: 1146

代码:

<?php 
class Migration_Create_sessions extends CI_Migration {
  public function up()
  {
    //Default codeigniter seesion table
    $fields = array(
      'session_id VARCHAR(40) DEFAULT ''0'' NOT NULL',
      'ip_address VARCHAR(45) DEFAULT ''0'' NOT NULL',
      'user_agent VARCHAR(120) NOT NULL',
      'last_activity INT(10) unsigned DEFAULT 0 NOT NULL',
      'user_data text NOT NULL'
    );
    $this->dbforge->add_field($fields);
    $this->dbforge->add_key('session_id', TRUE);
    $this->dbforge->create_table('ci_sessions');
    $this->db->query('ALTER TABLE `ci_sessions` ADD KEY `last_activity_idx` (`last_activity`)');  
  }
  //Rollback - drop entire table
  public function down()
  {
    $this->dbforge->drop_table('ci_sessions');
  }
}
?>

错误:

Error Number: 1146
Table 'bma.ci_sessions' doesn't exist
INSERT INTO `ci_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`,  `user_data`) VALUES ('', '127.0.0.1', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36', 1404181497, '')
Line Number: 330

试试这个:

$this->dbforge->create_table('ci_sessions', TRUE);

可选的第二个参数设置为TRUE,将"IF NOT EXISTS"子句添加到定义中这给出:

// gives CREATE TABLE IF NOT EXISTS ci_sessions

更改以下内容:

$db['default']['db_debug'] = TRUE;

默认情况下,这是真的。

如果将其更改为false,则迁移有效。