Phinx: Varchar not supported datatype

Created on 27 Aug 2018  路  5Comments  路  Source: cakephp/phinx

I was wondering why varchar isn't supported by phinx. My database makes extensive use of it, and I would love to be able to use the change() command instead of just running a query in up() and down()

Most helpful comment

tested on mysql, 'string' column type actually produce varchar
$this->table('my_table', ['id' => 'my_table_id'])->addColumn('name', 'string')->create();

perhaps it will be good to have varchar aliases in the column datatypes.

All 5 comments

tested on mysql, 'string' column type actually produce varchar
$this->table('my_table', ['id' => 'my_table_id'])->addColumn('name', 'string')->create();

perhaps it will be good to have varchar aliases in the column datatypes.

AdapterInterface::PHINX_TYPE_STRING is what should be used. This is the engine agnostic way to say you want a variable length string as not all database engines use the keyword varchar.

Wait what.... It's literally not supported?

It is, it's just not referred to varchar, rather string (or AdapterInterface::PHINX_TYPE_STRING which maps to string), which phinx uses as an engine agnostic way to refer to string/varchar columns.

        $this->table('tags')->addColumn('short_name', 'string', ['limit' => 30])
              ->create();

that will give you a table tags with a varchar(30) column.

@chrissound Please open a new issue if you have a problem to discuss. We don't encourage discussion in closed issues.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

igorsantos07 picture igorsantos07  路  30Comments

orderbynull picture orderbynull  路  19Comments

gms8994 picture gms8994  路  37Comments

l0gicgate picture l0gicgate  路  16Comments

saada picture saada  路  14Comments