Answer the question
In order to leave comments, you need to log in
Creating a table in Yii2?
The table with compound PRIMARY KEY, unique is necessary. The database query is:
CREATE TABLE `test33` (
id_1 MEDIUMINT,
id_2 MEDIUMINT,
PRIMARY KEY (id_1, id_2)
)
$this->createTable('test33', [
'id_1' => $this->primaryKey(),
'id_2' => $this->primaryKey(),
]);
'SQLSTATE[42000]: Syntax error or access violation:
1075 Incorrect table definition;
there can be only one auto column and it must be defined as a key
The SQL being executed was: CREATE TABLE `test3333` (
`id_1` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_2` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
)'
Answer the question
In order to leave comments, you need to log in
$this->createTable('test33', [
'id_1' => $this->integer(11)->notNull(),
'id_2' => $this->integer(11)->notNull(),
]);
$this->addPrimaryKey('pk-ids', 'test33, ['id_1', 'id_2']);
id_1=55
and id_2=66
will be unique
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question