2012-01-27 61 views
3

我想在Codeigniter中創建一個遷移文件,但是當我運行它時,它會拋出一個錯誤,無論我做什麼我都無法讓它運行。Codeigniter遷移自動和關鍵問題

class Migration_Add_users extends CI_Migration {  

public function up() 
{ 
     $this->dbforge->add_field(array(
      'USERS_id' => array(
       'type' => 'INT', 
       'constraint' => 5, 
       'auto_increment' => TRUE, 
      ), 
      'USERS_firstname' => array(
       'type' => 'VARCHAR', 
       'constraint' => '100', 
      ), 
      'USERS_surname' => array(
       'type' => 'VARCHAR', 
       'constraint' => '100', 
      ), 
      'USERS_email' => array(
       'type' => 'VARCHAR', 
       'constraint' => '150', 
       ), 
      'USERS_password' => array(
       'type' => 'VARCHAR', 
       'constraint' => '150', 
       ), 
      'USERS_password' => array(
       'type' => 'VARCHAR', 
       'constraint' => '150', 
       ), 
      'USERS_created' => array(
       'type' => 'DATETIME', 
       ), 
     )); 

     $this->dbforge->create_table('users'); 
     $this->dbforge->add_key('USERS_id', TRUE); 
    } 

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

這是錯誤

Error Number: 1075 
Incorrect table definition; there can be only one auto column and it must be defined as a key 

CREATE TABLE `users` ( 
`USERS_id` INT(5) NOT NULL AUTO_INCREMENT, 
`USERS_firstname` VARCHAR(100) NOT NULL, 
`USERS_surname` VARCHAR(100) NOT NULL, 
`USERS_email` VARCHAR(150) NOT NULL, 
`USERS_password` VARCHAR(150) NOT NULL, 
`USERS_created` DATETIME NOT NULL) DEFAULT 
CHARACTER SET utf8 COLLATE utf8_general_ci; 
+0

集USERS_id的一種方式主鍵 – ikromm 2012-01-27 14:48:53

+0

我需要在dbforge-> create_table之前運行dbforge-> add_key - dam it!必須有一種方法將此添加到dbforge-> add_field數組 – 2012-01-27 14:52:57

+0

是否需要在create table指令之前添加密鑰? – ikromm 2012-01-27 14:56:44

回答

2

我需要運行

dbforge->add_key 

dbforge->create_table 

必須有它添加到

dbforge->add_field 

陣列

1
'USERS_password' => array(
    'type' => 'VARCHAR', 
    'constraint' => '150', 
), 

出現兩次。

+0

你的權利,但那不是他的問題。謝謝 :-) – 2012-02-07 08:49:55