phpsqlcodeignitermigration

How to set Datetime as type for a column on Codeigniter migration


I am doing a migration file, and there is a field on a table the type of which should be DateTime, and the default value CURRENT_TIMESTAMP. What I have until now is the next:

'date'  => array(
    'type' => 'DATETIME',
),

I think it is right... but I still need set the default value... definitely, what I want to do is make the translation from SQL to codeigniter migration of this:

`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP

Thanks in advance.


Solution

  • I have found this answer in the codeigniter forum. Basically, it says that I can use created_at timestamp default current_timestampinstead of key->value array. And there are other interesant things like 'on update':

    'updated_at' => array(
         'type' => 'varchar',
         'constraint' => 250,
         'null' => true,
         'on update' => 'NOW()'
    ) 
    

    I hope it can to help anyone on future.