Composite primary keys
Closed this issue · 4 comments
I have realized that there is an issue with composite keys.
Apologies for not getting back to you.
Can you provide an example and I will look into it.
This is the example,
create table test(
columna varchar(20) not null,
columnb varchar(20) not null,
columnc varchar(20) not null,
primary key(columna,columnb)
);
Which generates this code
$this->createTable('{{%test}}', [
'columna' => 'VARCHAR(20) NOT NULL',
0 => 'PRIMARY KEY (`columna`)',
'columnb' => 'VARCHAR(20) NOT NULL',
1 => 'KEY (`columnb`)',
'columnc' => 'VARCHAR(20) NOT NULL',
], $tableOptions_mysql);
If it could work like this then better:
$this->createTable('{{%test}}', [
'columna' => Schema::TYPE_STRING . ' NOT NULL',
'columnb' => Schema::TYPE_STRING . ' NOT NULL',
'columnc' => Schema::TYPE_STRING . ' NOT NULL',
], $tableOptions_mysql);
Then add they keys now:
$this->addPrimaryKey('columna-columnb', 'news-cate', ['columna', 'columnb']);
Thanks.
Thanks, I will look into it and add an update or reply.
On Wed, Aug 10, 2016 at 11:31 PM, zeddarn notifications@github.com wrote:
This is the example,
create table test(
columna varchar(20) not null,
columnb varchar(20) not null,
columnc varchar(20) not null,
primary key(columna,columnb)
);Which generates this code
$this->createTable('{{%test}}', [
'columna' => 'VARCHAR(20) NOT NULL',
0 => 'PRIMARY KEY (columna
)',
'columnb' => 'VARCHAR(20) NOT NULL',
1 => 'KEY (columnb
)',
'columnc' => 'VARCHAR(20) NOT NULL',
], $tableOptions_mysql);If it could work like this then better:
$this->createTable('{{%test}}', [
'columna' => Schema::TYPE_STRING . ' NOT NULL',
'columnb' => Schema::TYPE_STRING . ' NOT NULL',
'columnc' => Schema::TYPE_STRING . ' NOT NULL',
], $tableOptions_mysql);Then add they keys now:
$this->addPrimaryKey('columna-columnb', 'news-cate', ['columna', 'columnb']);
Thanks.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#17 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AHVHsBn5ehnXXnZVM7XPRZJi1DIR40hiks5qesHDgaJpZM4Hpeth
.
Composite PKs have been added.
Regards