0

I'm new to Phinx can anyone tell me how to create 'myindex' so it is defined as

KEY myindex (column1, column2(767))

<?php


use Phinx\Migration\AbstractMigration;

class CreateMyTableTable extends AbstractMigration
{
    public function change() {
        $this->table('my_table')
           ->addColumn('column1', 'integer')
           ->addColumn('column2', 'text')
           ->addIndex(['column1', 'column2'], ['name' => 'myindex'])
           ->create();
    }
}

I want an index that looks like this

CREATE TABLE my_table (
   \`id\`int(11) unsigned NOT NULL AUTO_INCREMENT,
   \`column1\` int(11) NOT NULL,
   \`column2\` text,
   PRIMARY KEY (\`id\`),
   KEY \`myindex\` (\`column1\`, \`column2(767)\`)
)

Thanks in advance!

Cranespud
  • 91
  • 1
  • 5
  • You may need to write a raw query in order to achieve this. Have you fully vetted this section http://docs.phinx.org/en/latest/migrations.html#working-with-indexes? – Adam Mar 05 '18 at 21:16

1 Answers1

1

I could not find it in the docs but you can run raw SQL using $this->execute() so I ended up using it also to create views

hope this helps someone.

Cranespud
  • 91
  • 1
  • 5