Welcome Guest, Not a member yet? Register   Sign In
Db forge
#1

Hi sorry for english , i have two answer about db forge :


Code:
function create_users_table(){
         
     $this->load->dbforge();
     
     $fields = array(
          'id' => array(
                  'type' => 'INT',
                  'constraint' => 11,
                  'unsigned' => TRUE,
                  'auto_increment' => TRUE
          ),
          'email' => array(
                  'type' => 'VARCHAR',
                  'constraint' => '100',
                  'null' => FALSE,
                  'unique' => TRUE,
          ),
          'username' => array(
                  'type' =>'VARCHAR',
                  'constraint' => '50',
                  'default' => NULL
          ),
          'password_hash' => array(
                  'type' => 'VARCHAR',
                  'constraint' => '255'
          ),
          'activation_hash' => array(
                  'type' =>'VARCHAR',
                  'constraint' => '255',
                  'default' => NULL
          ),
          'password_reset_hash' => array(
                  'type' =>'VARCHAR',
                  'constraint' => '255',
                  'default' => NULL
          ),
          'data_registrazione' => array(
                  'type' =>'timestamp',
                  'constraint' => '6',
                  'default' => CURRENT_TIMESTAMP
          ),
          'id_ruolo' => array(
                  'type' =>'INT',
                  'constraint' => 11,
                  'null' => FALSE,
                  'default' => 1
          ),
          'id_stato' => array(
                  'type' =>'INT',
                  'constraint' => 11,
                  'null' => FALSE,
                  'default' => 1
          ),
          'last_login' => array(
                  'type' =>'DATETIME',
                  'null' => TRUE,
                  'default' => NULL
          )
     );
     
     $this->dbforge->add_field($fields);
     
     $this->dbforge->add_key('id', TRUE);
     
        $this->dbforge->create_table($this->users_table);
 }
 
The first , i have this error :
Error Number: 1067
Invalid default value for 'data_registrazione'
CREATE TABLE `users_codeigniter` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `email` VARCHAR(100) NOT NULL UNIQUE, `username` VARCHAR(50) NULL DEFAULT NULL, `password_hash` VARCHAR(255) NOT NULL, `activation_hash` VARCHAR(255) NULL DEFAULT NULL, `password_reset_hash` VARCHAR(255) NULL DEFAULT NULL, `data_registrazione` timestamp(6) NOT NULL DEFAULT 'CURRENT_TIMESTAMP', `id_ruolo` INT(11) NOT NULL DEFAULT 1, `id_stato` INT(11) NOT NULL DEFAULT 1, `last_login` DATETIME NULL DEFAULT NULL, CONSTRAINT `pk_users_codeigniter` PRIMARY KEY(`id`) ) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci
Filename: models/User_model.php
Line Number: 481


The second , how can i add a foreign key?
Reply
#2

"Invalid default value for 'data_registrazione'"
Base on error you have issue on the following line

data_registrazione' => array(
'type' =>'timestamp',
'constraint' => '6',
'default' => CURRENT_TIMESTAMP

CURRENT_TIMESTAMP is = "1970-01-01 00:00:01" for example and cannot put in field that has 6 constraint.
There are those who tell lies with meaning behind them and those meaning less lies!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB