3

Can you tell me please if is possible to set explicit length of integer column via Phinx migrations addColumn() method?

Documentation uses limit option with MysqlAdapter::INT_REGULAR like ['limit' => MysqlAdapter::INT_SMALL, 'signed' => false] but it automatically sets the length for column e.g. int(10).

But what should I do if I need int(11) e.g for foreign key column?

Thx.

tsg
  • 465
  • 5
  • 16
Čamo
  • 3,863
  • 13
  • 62
  • 114

1 Answers1

4

As I understood limit option MysqlAdapter::INT_REGULAR is something like predefined types in Phinx. But you can also use your own limit variable.

Here is an example:

// using Phinx 0.5.4
public function change() {
  $table = $this->table('papers');
  $table->addColumn('user_id', 'integer', ['limit' => 2])
        ->addColumn('book_id', 'integer') // by default will be int(11)
        ->addColumn('bank_id', 'integer', ['limit' => 32])
        ->create();

}

MySQL describe results:

+---------+---------+------+-----+---------+----------------+
| Field   | Type    | Null | Key | Default | Extra          |
+---------+---------+------+-----+---------+----------------+
| id      | int(11) | NO   | PRI | NULL    | auto_increment |
| user_id | int(2)  | NO   |     | NULL    |                |
| book_id | int(11) | NO   |     | NULL    |                |
| bank_id | int(32) | NO   |     | NULL    |                |
+---------+---------+------+-----+---------+----------------+

To get more information please check the source code of getSqlType() and source code of getPhinxType() functions.

tsg
  • 465
  • 5
  • 16