method hasIndex returns false always for composit index
indexes created with,
ALTER TABLE my_table ADD CONSTRAINT sampleindex UNIQUE (field1,field2)
now inside a migrations 'up' method, $Table = $this->table('my_table'); $Table->hasIndex('sampleindex');// returns false
Try using hasIndexByName('sampleindex') instead.
MySQL?
Yeah On Jan 6, 2016 12:24 AM, "Wanderson Camargo" [email protected] wrote:
MySQL?
— Reply to this email directly or view it on GitHub https://github.com/robmorgan/phinx/issues/728#issuecomment-169088529.
UTSL, method hasIndex must receive columns, not the name of the index.
So, $Table->hasIndex(['field1', 'field2']) should work.
Yeah I'm sorry for bad info; I should've looked closer :(
hasIndexByName is an adapter method, so you have to run it on the table's adapter.
$table = $this->table('my_table');
$exists = $table->getAdapter()->hasIndexByName($table->getName(), 'my_index_name');
I run into the exact same thing.
Its confusing. Perhaps hasIndex should throw an exception like ~"column not found" or similar.
Then you 1st cannot accidentally provide an index name and 2nd cannot accidentally provide non-existing columns (f.e on typo).
Thanks, /cottton
EDIT
or|or pls add the ::hasIndexByName to the \Phinx\Db\Table like
// \Phinx\Db\Table
public function hasIndexByName($name)
return $this->getAdapter()->hasIndexByName($this->getName(), $name);