CodeIgniter - 错误号码:1146

时间:2014-07-01 02:37:09

标签: php codeigniter

代码:

<?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

2 个答案:

答案 0 :(得分:0)

试试这个:

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

设置为TRUE的可选第二个参数会在定义中添加“IF NOT EXISTS”子句 这给出了:

// gives CREATE TABLE IF NOT EXISTS ci_sessions

答案 1 :(得分:0)

更改以下内容:

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

默认情况下,确实如此。

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