3

I am trying to figure out how best to modify a MySQL Table's existing Column using the CakePHP Migrations plugin. I do not need to add or drop the column, I simply want to modify a string column's length.

Currently the column is defined as a varchar(50); I am repurposing the column and wish to define it as varchar(2000).

The goal of the migration is to be part of an automated deployment taking place on a standard CakePHP web app installation on a typical web server.

Near as I can tell, it looks like the only way (other than an ALTER statement) to accomplish this using the Migrations Plugin would be to:

  1. rename the column
  2. add the new column
  3. Move/copy the existing data to the new column
  4. drop the old column

Perhaps I have missed the discussion in the documents and countless tutorials and how to's out there on a better way to accomplish this, but this seems like a cumbersome and self defeating method.

I have been through both the CakePHP Migration Plugin's documentation and the Phinx's documentation but am failing to see the recommended method for this change. I appreciate any input for this.

Kingsolmn
  • 1,868
  • 2
  • 23
  • 39

1 Answers1

9

Unfortunately the Phinx docs aren't that complete, there seem to be various undocumented methods, like the one you are looking for: \Phinx\Db\Table::changeColumn()

The following should work

$table = $this->table('table_name');
$table->changeColumn('column_name', 'string', [
    'limit' => 2000
]);
$table->update();
ndm
  • 59,784
  • 9
  • 71
  • 110
  • This is perfect, thanks for the speedy reply! This looks like exactly what I'm looking for! – Kingsolmn Nov 22 '15 at 17:19
  • Exactly what I needed, worked like a charm! Thanks for the resource links too, lead me to some great info to solve an unrelated issue I had. – Kingsolmn Nov 25 '15 at 19:54