你能告诉我是否可以通过 Phinx 迁移 addColumn()
方法设置整数列的显式长度吗?
文档使用 MysqlAdapter::INT_REGULAR
的限制选项,如 ['limit' => MysqlAdapter::INT_SMALL, 'signed' => false]
但它会自动设置列的长度,例如int(10)
。
但是如果我需要 int(11)
例如外键列,我该怎么办?
谢谢。
最佳答案
据我了解limit option MysqlAdapter::INT_REGULAR
类似于 Phinx 中的预定义类型。但您也可以使用自己的 limit
变量。
这是一个例子:
// 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 描述结果:
+---------+---------+------+-----+---------+----------------+
| 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 | |
+---------+---------+------+-----+---------+----------------+
要获取更多信息,请查看 source code getSqlType()
和 source code getPhinxType()
函数。
关于php - Phinx 迁移 - 整数列的显式长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37279810/