Phinx: Method to add unique constraint for postgres

Created on 14 Jan 2014  路  3Comments  路  Source: cakephp/phinx

DB: postgres

$table = $this->table('test_table')
->addColumn('test_field', 'string', array('limit' => 10))
->save();

$this->execute("ALTER TABLE ONLY test
ADD CONSTRAINT test_key UNIQUE (test_field);");

Has a method to add unique index. But could not see a method to add constraint, so i am doing a separate alter table to do it. Is there a method to add unique constraint?

Most helpful comment

:+1: for this feature!
ADD CONSTRAINT is essential.
"CREATE INDEX" is different of "ADD CONSTRAINT".

Constraints have a name.

All 3 comments

Yep, I guess what you are looking for is..

$table->addIndex('column-name', array('unique' => true))

I think addIndex is not what sooners87 is looking for...
He is looking for a method to add constraint, not index.

:+1: for this feature!
ADD CONSTRAINT is essential.
"CREATE INDEX" is different of "ADD CONSTRAINT".

Constraints have a name.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

czogori picture czogori  路  4Comments

dfsoeten picture dfsoeten  路  3Comments

otaruMendez picture otaruMendez  路  3Comments

camohub picture camohub  路  5Comments

omer-sds picture omer-sds  路  4Comments