0
我嘗試做以下以下遷移表:如何添加檢查約束遷移笨的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)
有沒有什麼建議?