Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Change created_at field datatype to datetime
  • Hi,
    By default, Oil set datatype of created_at and updated_at fields as int. I want to change created_at datatype to datetime. How to do it via Oil command.
    Hoping for rapid response.

    Thanks in advance.
  • I don't think it's configurable.

    I would strongly advice against using the datetime datatype, it's a nightmare to work with.
  • I suggest the same: if you use the timestamp (the int that is saved into DB) you are able to convert it in every kind od datetime you want, so if you have to use different date (like in a blog, where in the link usually is used the year and the month link "mysuperblog.com/post/2012/11/super-title.html") it takes seconds instead of hours to parse the datetime.
  • HarroHarro
    Accepted Answer
    But if you insist, --mysql-timestamp will do the trick. So it is configurable.
  • I know its not a good approach to use datetime instead of int but its client request ...
    Harro, Can you please provide me the whole oil command ?



  • Thanks Harro --mysql-timestamp did the job.
    One more thing, Is it possible to alter existing table through oil to use --mysql-timestamp .. If yes, how ?
  • Not the way you think, oil just generates migrations, it doesn't change the database.

    You can start a the Oil console on the commandline and then just type a DB::query() command, but I think it's easier to do it directly either through the mysql binary or a tool like phpmyadmin.
  • Hi all,

    Indeed they are a mess to work with those datetime objects (but somethimes customers ask for exports and they don't like those timestamps), I have created a migration that scans your db for created_at and updated_at fields when the migration finds them it sets the types to datetime( without loss of data).
    after the migration you just run trough your models setting every 'mysql_timestamp' => true,
    then your good to go.
    Here's the gist:

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion