[英]How to add new column (and populate it) in Entity Framework __MigrationHistory
I'm using Entity Framework 6, my case is very simple, I need to add a new column in the __MigrationHistory
table that should have the datetime (like a timestamp) of the created date. 我正在使用Entity Framework 6,我的情况很简单,我需要在__MigrationHistory
表中添加一个新列,该列应具有创建日期的日期时间(如时间戳记)。
I read some examples where it says how to rename MigrationHistory
or even rename the primary key column - this is not what I want, so please don't give me that example ( https://msdn.microsoft.com/en-us/data/dn456841.aspx ) 我读了一些例子,上面写着如何重命名MigrationHistory
甚至重命名主键列-这不是我想要的,所以请不要给我这个例子( https://msdn.microsoft.com/zh-cn/数据/dn456841.aspx )
I just need to add a createdDate
column, and when you use update-database -script
that new column should be equal to dateTime.now()
. 我只需要添加一个createdDate
列,并且当您使用update-database -script
,新列应等于dateTime.now()
。
Does anyone know how to achieve this? 有谁知道如何实现这一目标?
Thanks! 谢谢!
The MigrationId
column already as the datestamp of the migration creation. MigrationId
列已作为迁移创建的日期戳。
MigrationId
201407221811141_InitTables
If you are trying to get the date of when the migration was applied you should be able to create a migration that runs a SQL script to add a column with a default value: 如果要获取应用迁移的日期,则应该能够创建一个运行SQL脚本的迁移,以添加具有默认值的列:
pseudo code: 伪代码:
Migration {
Up() {
SQL('Alter table __MigrationHistory add createdDate datetime')
SQL('Alter table __MigrationHistory ADD CONSTRAINT CONSTRAINT_NAME DEFAULT GETDATE() FOR createdDate')
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.