CakePHP 迁移 - 如何指定比例和精度
CakePHP Migrations - How to specify scale and precision
我是 运行 CakePhp 2.7,带有迁移插件和 Postgresql 数据库。
创建 'number' 类型的字段并指定长度 15,4(比例 15,精度 4 - 或任何长度)实际上并不会创建具有该精度 and/or 比例的字段。
...
'license_fee' => array(
'type' => 'number',
'null' => true,
'length' => '15,6',
'default' => 0
),
...
创建的字段类型正确(数字),但没有 scale/precision 这里是创建字段的 Postgres 描述。
license_fee | numeric | default 0
我期待看到的是这个
license_fee | numeric(15,6) | default 0
我也尝试使用 'type' => 'decimal' 但同样的事情发生了。迁移插件可能不支持此功能,但我只想知道是否有人确切知道发生了什么。
经过进一步调查和 Cake Development Corp 的一些帮助后,事实证明指定精度和比例的正确方法是使用 "limit" 而不是像我尝试的那样 "length"。所以应该是这样的:
'license_fee' => array(
'type' => 'number',
'null' => true,
'limit' => '15,6', //this is where I was wrong by using length
'default' => 0
),
如果使用 'type' => 'decimal' 这实际上是相同的数据类型,这也将起作用。最终结果如预期:
license_fee | numeric(15,6) | default 0
我希望这对某人有用。
在此处找到:http://docs.phinx.org/en/latest/migrations.html
为了创建一个 : decimal(9,3)
$table->addColumn('distance', 'decimal', [
'default' => null,
'null' => false,
'precision'=>9,
'scale'=>3
]);
我是 运行 CakePhp 2.7,带有迁移插件和 Postgresql 数据库。 创建 'number' 类型的字段并指定长度 15,4(比例 15,精度 4 - 或任何长度)实际上并不会创建具有该精度 and/or 比例的字段。
...
'license_fee' => array(
'type' => 'number',
'null' => true,
'length' => '15,6',
'default' => 0
),
...
创建的字段类型正确(数字),但没有 scale/precision 这里是创建字段的 Postgres 描述。
license_fee | numeric | default 0
我期待看到的是这个
license_fee | numeric(15,6) | default 0
我也尝试使用 'type' => 'decimal' 但同样的事情发生了。迁移插件可能不支持此功能,但我只想知道是否有人确切知道发生了什么。
经过进一步调查和 Cake Development Corp 的一些帮助后,事实证明指定精度和比例的正确方法是使用 "limit" 而不是像我尝试的那样 "length"。所以应该是这样的:
'license_fee' => array(
'type' => 'number',
'null' => true,
'limit' => '15,6', //this is where I was wrong by using length
'default' => 0
),
如果使用 'type' => 'decimal' 这实际上是相同的数据类型,这也将起作用。最终结果如预期:
license_fee | numeric(15,6) | default 0
我希望这对某人有用。
在此处找到:http://docs.phinx.org/en/latest/migrations.html
为了创建一个 : decimal(9,3)
$table->addColumn('distance', 'decimal', [
'default' => null,
'null' => false,
'precision'=>9,
'scale'=>3
]);