Using dbforge? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Using dbforge? (/showthread.php?tid=34027) |
Using dbforge? - El Forum - 09-16-2010 [eluser]chefnelone[/eluser] Hello I'm creating a new table using dbforge. If I tried with this code, it works fine: Code: $fields = array( But it FAILS if I tried to set the 'default' value to 'CURRENT_TIMESTAMP' for the field 'date'. Tried with: Code: ... How can I solve this? thanks Using dbforge? - El Forum - 09-16-2010 [eluser]n0xie[/eluser] Did you try without the " ? Code: ... Using dbforge? - El Forum - 09-16-2010 [eluser]chefnelone[/eluser] [quote author="n0xie" date="1284658880"]Did you try without the " ? Code: ... I tried, but.. no working. Code: ... Using dbforge? - El Forum - 09-16-2010 [eluser]WanWizard[/eluser] It's not going to work, because the dbforge database driver assumes it's a literal (string, number), an places any default value in single quotes. The work-around is: Code: 'date' => array("date TIMESTAMP DEFAULT CURRENT_TIMESTAMP") if you pass a string as array value instead of an creating an associated array, the string is used as-is. Note that it is likely that this breaks database portability. This is explained in the user guide, database library, dbforge, add_field. Using dbforge? - El Forum - 09-16-2010 [eluser]chefnelone[/eluser] [quote author="WanWizard" date="1284669760"]It's not going to work, because the dbforge database driver assumes it's a literal (string, number), an places any default value in single quotes. The work-around is: Code: 'date' => array("date TIMESTAMP DEFAULT CURRENT_TIMESTAMP") if you pass a string as array value instead of an creating an associated array, the string is used as-is. Note that it is likely that this breaks database portability. This is explained in the user guide, database library, dbforge, add_field.[/quote] hum.. something is wrong. I tried with: (both fail...) Code: 'fecha' => array("fecha TIMESTAMP DEFAULT 'CURRENT_TIMESTAMP'") Code: 'fecha' => array("fecha TIMESTAMP DEFAULT CURRENT_TIMESTAMP") Using dbforge? - El Forum - 09-16-2010 [eluser]WanWizard[/eluser] What's the definition of fail? Error messages? What's the output of $this->db->last_query()? What database engine are you using? Using dbforge? - El Forum - 06-17-2011 [eluser]ipsod[/eluser] This should work: Code: 'date' => array('type=>"TIMESTAMP DEFAULT CURRENT_TIMESTAMP") Note, though, MySQL table can only have a single field that has CURRENT_TIMESTAMP as default, according to errors. Using dbforge? - El Forum - 08-02-2012 [eluser]Unknown[/eluser] Not sure when this changed but... to do this now (CI Version: 2.1.2), the code should be as follows: Code: $this->dbforge->add_field(array( ... with extra fields (id, name) to give context. So you can pass the whole definition for a field as a string instead of passing an array. Also - if you just pass the string 'id' it'll auto convert to : Code: 'id' => array( |