1

我正在运行带有迁移插件和 Postgresql 数据库的 CakePhp 2.7。创建“数字”类型的字段并指定长度 15,4(比例 15,精度 4 - 或任何长度)实际上不会创建具有该精度和/或比例的字段。

          ...
 'license_fee' => array(
   'type' => 'number',
   'null' => true,
   'length' => '15,6',
   'default' => 0
  ),
        ...

该字段是使用正确的类型(数字)创建的,但没有比例/精度这里是创建字段的 Postgres 描述。

license_fee               | numeric | default 0

我期待看到的是这个

license_fee               | numeric(15,6) | default 0

我也尝试使用 'type' => 'decimal' 但同样的事情发生了。迁移插件可能不支持此功能,但我只想知道是否有人确切知道发生了什么。

4

2 回答 2

6

在这里找到:http: //docs.phinx.org/en/latest/migrations.html

为了创建一个:十进制(9,3)

$table->addColumn('distance', 'decimal', [
            'default' => null,
            'null' => false,
            'precision'=>9,
            'scale'=>3
        ]);
于 2017-03-21T09:45:55.073 回答
2

经过进一步调查和 Cake Development Corp. 的一些帮助。事实证明,指定精度和比例的正确方法是像我尝试的那样使用“限制”而不是“长度”。所以它应该是这样的:

'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

我希望这对某人有用。

于 2016-10-10T19:12:34.177 回答