LoginSignup
5
5

More than 5 years have passed since last update.

CakePHP3のマイグレーションで複合ユニークキー設定

Posted at

addIndexで複合ユニークキーに設定したいカラムと['unique' => true]を指定する。

$table = $this->table('table_name');

$table->addColumn('company_id', 'integer', ['limit' => 11])
      ->addColumn('employee_id', 'integer', ['limit' => 11])
      ->addIndex(['company_id', 'employee_id'], ['unique' => true]);

マイグレーション関連はCakeのCookbookよりPhinxのマニュアルを見た方が色々載っているので良い。

(参考) http://docs.phinx.org/en/latest/migrations.html#creating-a-table

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5