Dbforge在CodeIgniter中导致错误1064

时间:2014-05-07 18:25:55

标签: php mysql codeigniter

我已经编写了这段代码,用于CodeIgniter中的Dbforge。

$fields = array(

                    'time_stamp' => array(
                                             'type' => 'STRING',
                                             'constraint' => 9,
                                              'null' => TRUE
                                      ),

                    'curr_property' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),

                    'curr_property_cost' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),

                    'day_property' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_property_cost' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_solar_generating' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_solar_export' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_solar_generated' => array(
                                               'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                     'day_solar_export' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_chan1' => array(  
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE
                                      ),

                    'curr_chan2' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'curr_chan3' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_chan1' => array(
                                              'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_chan2' => array(
                                               'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      ),

                    'day_chan3' => array(
                                             'type' => 'INT',
                                             'constraint' => 5, 
                                             'unsigned' => TRUE,
                                             'auto_increment' => TRUE

                                      )

                );


                $this->dbforge->add_field($fields);

                $this->dbforge->create_table($this->table_name);

我继续收到以下错误

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'STRING(9) NULL, `curr_property` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr' at line 2

CREATE TABLE `admin_tmp` ( `time_stamp` STRING(9) NULL, `curr_property` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_property_cost` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_property` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_property_cost` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_solar_generating` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_solar_export` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_solar_generated` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_solar_export` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_chan1` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_chan2` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `curr_chan3` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_chan1` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_chan2` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT, `day_chan3` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

我查找了与错误相关的原因否,但除了this link之外,我无法找到与我的问题相关的任何内容。如果有人能告诉我什么是错的,将不胜感激。

1 个答案:

答案 0 :(得分:1)

STRING在MySQL中不是有效的数据类型。我认为您正在寻找CHARVARCHAR