Welcome Guest, Not a member yet? Register   Sign In
Migration
#1

[eluser]cerberus478[/eluser]
I'm doing a tutorial on migration and for some reason I'm getting this error
Quote:Error Number: 1146

Table 'demo.ci_sessions' doesn't exist

INSERT INTO `ci_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`, `user_data`) VALUES ('0cd5628dee526ad05f2b2aaa7d13a35c', '::1', 'Mozilla/5.0 (Windows NT 6.0; rv:25.0) Gecko/20100101 Firefox/25.0', 1384368848, '')

Filename: C:\wamp\www\afishinsea\system\database\DB_driver.php

Line Number: 330

This is my controller
Code:
<?php
class Migration extends Admin_Controller
{

public function __construct ()
{
  parent::__construct();
}

public function index ()
{
  $this->load->library('migration');
  if (! $this->migration->current()) {
   show_error($this->migration->error_string());
  }
  else {
   echo 'Migration worked!';
  }

}

}

and this is the migration php file, its located in the migrations folder that I created
Code:
<?php
class Migration_Create_Sessions extends CI_Migration {

  public function up()
  {
    $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`)');  
  }

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

}
#2

[eluser]noideawhattotypehere[/eluser]
I think you have to either manually create session table or make a migration > swap to database sessions after that.
#3

[eluser]CroNiX[/eluser]
I'm not sure you are using dbforge::add_field() correctly, either. The user guide shows passing an array of arrays containing individual field parameter definitions. You are passing an array of raw SQL field definitions.

Instead of
'session_id VARCHAR(40) DEFAULT \'0\' NOT NULL'

it should be something like
Code:
array(
  'session_id' => array(
    'type' => 'varchar',
    'constraint' => 40,
    'default' => '0',
    'null'  => FALSE
  ),
  'ip_address' => array(
    //parameters for this field...
  )
)




Theme © iAndrew 2016 - Forum software by © MyBB