我想在postgres数据库中创建一个带有ENUM字段的表。
通常,当我们在postgresql中创建枚举时,我们将枚举命名为enum,以及我们要设置的列,选择该枚举名称。但在Codeigniter里我该怎么做呢?
下面是我的代码:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Migration_Admin_Locations extends CI_Migration {
public function up()
{
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'null' => FALSE,
'auto_increment'=>TRUE,
'constraint' => 11,
),
'location_name' => array(
'type' => 'VARCHAR',
'constraint' => 50,
'null' => TRUE,
),
'tenant_id' => array(
'type' => 'INT',
'null' => TRUE,
),
'description' => array(
'type' => 'VARCHAR',
'constraint' => 128,
'null' => TRUE,
),
'is_default' => array(
'type' => 'ENUM("a","b","c")',
'default' => "a",
'null' => TRUE,
),
));
$this->dbforge->add_key('id');
$this->dbforge->create_table('admin_locations');
$query = $this->db->get('admin_locations');
$res=$query->num_rows();
if($res==0)
{
$data = array(
'id'=>"1",
'location_name'=>"default site",
'tenant_id'=>"1",
'description'=>"This is default site for portal",
'is_default'=>"a",
);
$this->db->insert('admin_locations', $data);
}
}
public function down()
{
$this->dbforge->drop_table('admin_locations');
}
}但这会触发一个错误:
遇到严重程度PHP错误:警告 消息: pg_query():查询失败: ERROR: type "enum“不存在第6行:"is_default”ENUM("a“、"b”、"c")默认值'no‘NULL ^ 文件名: postgre/postgre_driver.php 线路号码: 242 回溯:
发布于 2019-01-07 10:51:31
发布于 2019-01-07 10:03:00
在enum中,不能传递空数据..。这是sql错误..。改变is_default阵列
'null' => TRUE,至
'null' => FALSE,https://stackoverflow.com/questions/54071841
复制相似问题