views:

51

answers:

1

I'm using Symfony 1.4 with Doctrine.

Here's my initial schema:

Page:
  tableName: page
  columns:
    ref:
      type: string(50)
      notnull: true
      unique: true

I'd like to remove the index on the ref column using migrations. So the schema becomes:

Page:
  tableName: page
  columns:
    ref:
      type: string(50)
      notnull: true

And my migration file is something like:

class Changepageref extends Doctrine_Migration_Base
{
  public function up()
  { 
    $this->removeIndex('page','ref');
  }

  public function down()
  {
    $this->addIndex('page','ref', array('fields'=>array('ref'=>array()),'unique'=>true));
  }
}

But this won't work when I run it because it's looking for an index named "ref_idx". But if I look at my database, doctrine created an index named "ref", not "ref_idx".

What am I doing wrong?

A: 

You can define the default naming of the indexes: the default is "_idx". You can change in on the connection manager.

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/configuration/en#naming-convention-attributes shows it like

$manager->setAttribute(Doctrine_Core::ATTR_IDXNAME_FORMAT, '%s_index');

Try to set it there and it should be persistent throughout your application with the index names.

DrColossos
If the default is "_idx", how come the index created by Dotrine was "ref" and not "ref_idx" ?
Guillaume Flandre
Maybe it's a bug or some wired config or alike. If you set the IDX format, is it working? Another case could be that the `addIndex()` does not use the IDX_FORMAT variable so you need to stick to the given schema
DrColossos