Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Grails中带时间戳的数据库迁移_Spring_Grails_Grails 2.0_Grails Plugin - Fatal编程技术网

Spring Grails中带时间戳的数据库迁移

Spring Grails中带时间戳的数据库迁移,spring,grails,grails-2.0,grails-plugin,Spring,Grails,Grails 2.0,Grails Plugin,我使用的是Grails2.2.4和mysql数据库,以及 对于数据库中持久的给定类: class User { String name } 然后我补充说: Date lastUpdated 而且: grails dbm-gorm-diff 2013-09-09-lastUpdated.groovy -add grails dbm-update 但是当我查看我的数据库时,我可以看到0000-00-00:00:00 如何获取有效日期(例如,新日期)作为默认值?尝试设置autoTimest

我使用的是Grails2.2.4和mysql数据库,以及

对于数据库中持久的给定类:

class User {
   String name
}
然后我补充说:

Date lastUpdated
而且:

grails dbm-gorm-diff 2013-09-09-lastUpdated.groovy -add
grails dbm-update
但是当我查看我的数据库时,我可以看到0000-00-00:00:00


如何获取有效日期(例如,新日期)作为默认值?

尝试设置autoTimestamp默认情况下可能为false:

static mapping = {
   autoTimestamp true
   ...
}
或者只需在更新前使用:

def beforeUpdate() {
   lastUpdated = new Date()
}

这不起作用所有现有行中的lastUpdated仍然是0000-00-00 00:00:00。如果在创建新用户时需要填写lastUpdated字段,请在插入之前尝试使用def。您有其他想法吗?使用相同字段创建测试类,并在不使用dbm-gorm-diff的情况下为其创建自己的迁移脚本。检查方法是否有效。另一个解决方案是在数据库中创建触发器,以便在每次数据插入或更新时更新lastUpdate字段,但这是一件非常复杂的事情。