5

Here is my table definition for Propel schema. Column modified has timestamp type (DateTime in PHP) and I'd like to assign a default value to now. I've tried setting it to "now" but I'm getting an error using propel-gen insert-sql command:

"Syntaxt error or access violation: 1067 Invalid default value for 'modified'.

Anyone knows how I can set default value to now for a timestamp column in Propel?

<table name="mashup_setting">
   <!-- omitted previous column definition -->
   <column name="modified" type="timestamp" required="true" defaultValue="now" />
</table>
halfer
  • 19,824
  • 17
  • 99
  • 186
gremo
  • 47,186
  • 75
  • 257
  • 421

3 Answers3

14

In newer Propel versions you can specify you column like so:

<column name="created" type="TIMESTAMP" defaultExpr="CURRENT_TIMESTAMP" />

It's then cross-db compatible.

Marc J. Schmidt
  • 8,302
  • 4
  • 34
  • 33
5

Change the name to "updated_at" which is a special field in Propel that will automatically be updated to NOW() whenever you update the field. "created_at" is also similar and will do the same thing when your object is created.

In your model you can always proxy "modified" or getModified() to getUpdatedAt() to complete your functionality.

If you have to have "modified" as the name for your column, you need to write a behavior, which I think is more work that you need to accomplish this. You can find information about behaviors here.

http://www.symfony-project.org/cookbook/1_2/en/behaviors

richrosa
  • 823
  • 6
  • 5
2

The docs at http://propelorm.org/behaviors/timestampable.html don't specify if this is available in 1.6 but add this to schema and build:

<behavior name="timestampable" />

The model now has two new columns, created_at and updated_at, that store a timestamp automatically updated on save:

$obj->save();
echo $obj->getCreatedAt(); // 2009-10-02 18:14:23
echo $obj->getUpdatedAt(); // 2009-10-02 18:14:25
jerrygarciuh
  • 21,158
  • 26
  • 82
  • 139