如何添加检查约束迁移Codeigniter PostgreSQL


How add Check Constraints migration Codeigniter PostgreSQL

我正在尝试做下面的迁移表:

SQL:

CREATE TABLE 
(
    product_no integer,
    name text,
    price numeric positive_price CHECK (price> 0) 
);
PHP:

$this->dbforge->drop_table('products', true);
$this->dbforge->add_field(array(
   'product_no' => array(
      'type' => 'INTEGER'
    ),
   'name' => array(
      'type' => 'VARCHAR',
      'constraint' => '20'
    ),
   'price' => array(
      'type' => 'NUMERIC',
      'constraint' => 'CONSTRAINT positive_price CHECK (price > 0)'
   )
));
$this->dbforge->add_key('product_no', TRUE);
$this->dbforge->create_table('products');

但是生成的查询无效:

SQL:

CREATE TABLE "products" ( "product_no" INTEGER NOT NULL, "name" VARCHAR(20) NOT NULL, "price" NUMERIC(positive_price CHECK (price > 0)) NOT NULL )

任何建议吗?

花了一些时间思考后找到了解决方案。要生成与示例相同的表,只需在完成课程后添加'CHECK (price> 0)'即可。

PHP:

'price' => array(
   'type' => 'NUMERIC CHECK (price > 0)'
)