Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter 2.2.2 dbforge生成默认值'';无效的_Php_Codeigniter_Codeigniter 2 - Fatal编程技术网

Php Codeigniter 2.2.2 dbforge生成默认值'';无效的

Php Codeigniter 2.2.2 dbforge生成默认值'';无效的,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,它看起来像是对CI数据库驱动程序中的_process_fields()函数的限制。它说: <?php defined("BASEPATH") or exit("No direct script access allowed"); class Migration_Create_clients_categories_table extends CI_Migration { public function up() { $this->dbforge-&g

它看起来像是对CI数据库驱动程序中的_process_fields()函数的限制。它说:

<?php defined("BASEPATH") or exit("No direct script access allowed");

class Migration_Create_clients_categories_table extends CI_Migration {

    public function up()
    {
        $this->dbforge->add_field(array(
            'id' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => TRUE,
                'auto_increment' => TRUE,
            ),
            'parent_id' => array(
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => TRUE,
                'default' => NULL,
                'null' => TRUE,
            ),
        ));
        $this->dbforge->add_key('id', TRUE);

        $this->dbforge->create_table('clients_categories');
    }

    public function down() 
    {
        $this->dbforge->drop_table('clients_categories');
    }
}
…所以这些引号被硬编码到MySQL调用中

但是(对我最初的回答进行激进的编辑):如果一个字段可以为NULL,并且没有设置默认值,那么MySQL将默认为NULL,如果你明白我的意思的话

从手册中:

如果列定义不包含显式默认值,MySQL将按如下方式确定默认值:

如果该列可以将NULL作为值,则该列将使用显式默认NULL子句定义

因此,使用迁移或dbForge不能做到这一点基本上是好的

if (array_key_exists('DEFAULT', $attributes))
{
    $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
}