CakePHP 迁移 - 如何指定比例和精度 [英] CakePHP Migrations - How to specify scale and precision
问题描述
我正在运行带有迁移插件和 Postgresql 数据库的 CakePhp 2.7.创建数字"类型的字段并指定长度 15,4(小数位数 15,精度 4 - 或任何长度)实际上并不会创建具有该精度和/或小数位数的字段.
I'm Running CakePhp 2.7 with Migrations Plugin and a Postgresql DB. Creating a field of type 'number' and specifying length 15,4 (scale 15, precision 4 - or any length) does not actually create the field with that precision and/or scale.
...
'license_fee' => array(
'type' => 'number',
'null' => true,
'length' => '15,6',
'default' => 0
),
...
该字段是用正确的类型(数字)创建的,但没有标度/精度,这里是所创建字段的 Postgres 描述.
The field is created with the correct type (numeric) but with no scale/precision here is the Postgres description of the created field.
license_fee | numeric | default 0
我期待看到的是这个
license_fee | numeric(15,6) | default 0
我也尝试使用 'type' => 'decimal' 但同样发生了.这可能不受迁移插件的支持,但我只想知道是否有人确切知道发生了什么.
I also tried using 'type' => 'decimal' but same happened. This might not be supported by the migrations plugin but I just want to know if anyone knows for sure what's going on.
推荐答案
经过进一步调查和 Cake Development Corp. 的一些帮助,结果证明指定精度和比例的正确方法是使用限制"而不是长度"就像我在尝试一样.所以应该是这样的:
After further investigation and some help from Cake Development Corp. It turns out that the correct to way specify precision and scale is by using "limit" not "length" like I was attempting. So it should be like this:
'license_fee' => array(
'type' => 'number',
'null' => true,
'limit' => '15,6', //this is where I was wrong by using length
'default' => 0
),
如果使用 'type' => 'decimal' 这实际上是相同的数据类型,这也将起作用.最终结果如预期:
This will work also if using 'type' => 'decimal' which is actually the same datatype. The end result is as expected:
license_fee | numeric(15,6) | default 0
我希望这对某人有用.
这篇关于CakePHP 迁移 - 如何指定比例和精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!