PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 14, 2022

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

 April 14, 2022     codeigniter, migration, php, sql     No comments   

Issue

I am doing a migration file, and there is a field on a table wich type 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.



Answered By - Eloy Fernández Franco
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing