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;
セットにこれを追加する方法があるに違いありません
前
を実行するために必要な主キー – ikromm
必要dbforge-> add_keyをdbforge-> create_tableの前に実行するには - dam it!これをdbforge-> add_field配列 –
に追加するには、create tableディレクティブの前にキーを追加する必要がありますか? – ikromm