Php Codeigniter迁移自动和关键问题
我试图在Codeigniter中创建一个迁移文件,但当我运行它时,它会抛出一个错误,无论我做什么,我都无法让它运行Php Codeigniter迁移自动和关键问题,php,codeigniter,migration,Php,Codeigniter,Migration,我试图在Codeigniter中创建一个迁移文件,但当我运行它时,它会抛出一个错误,无论我做什么,我都无法让它运行 class Migration_Add_users extends CI_Migration { public function up() { $this->dbforge->add_field(array( 'USERS_id' => array( 'type' => 'I
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;
出现两次。我需要运行
dbforge->add_key
在
dbforge->create_table
一定有办法把它添加到
dbforge->add_field
array将USERS\u id设置为主键我需要运行dbforge->add\u键,然后再运行dbforge->create\u表-dam it!必须有一种方法将其添加到dbforge->add_字段数组是否需要在create table指令之前添加键?
dbforge->add_field