【发布时间】:2017-10-02 11:26:12
【问题描述】:
让我们支持我有一个迁移,我们称之为001_Create_organization_users.php 有两列,X,Y,它们都是一个组合的 PK:
<?php
namespace Fuel\Migrations;
class Create_organizations_users
{
public function up()
{
\DBUtil::create_table('organizations_users', array(
'X' => array('constraint' => 11, 'type' => 'int'),
'Y' => array('constraint' => 11, 'type' => 'int')
), array('X', 'Y')); // Primary Key
}
// Other functions
}
然后我用不同的迁移向该表添加一列,我们称之为002_Add_column_to_organization_users.php
<?php
namespace Fuel\Migrations;
class Add_column_to_organization_users.php
{
public function up()
{
$fields = array(
'Z' => array(
'constraint' => 11, 'type' => 'int'),
);
\DBUtil::add_fields('organizations_users', $fields);
//....
}
我能否以某种方式编辑该迁移,以便我可以将列“Z”添加为具有先前输入的键的主键,以便我的最终主键是X,Y,Z?
【问题讨论】:
-
您是说需要将主要设为
X,Y,Z而不是X,Y吗? -
@Ravi 是的,在我通过第二次迁移添加列
Z后,我需要将该字段添加为现有主键的一部分。
标签: mysql sql primary-key composite-primary-key alter