I'm trying to add a default value to this but for some reason EF5 Stuck one in there already in the table creation even though I didn't specify this. Why did it do it? what is the best way to remove it an add this
public override void Up()
{
AlterColumn("dbo.tb", "DateCreated", c => c.DateTime(defaultValueSql: "GETDATE()"));
}
thanks, I know I can do that but I wanted to do all the DB mods through the fluent migration, which seems like a best practice since each developer oculd then run his own DB without me having to tell them to do manual stuff.
What do you think?
Mabye in future I shold avoid [required] metadatatags since it seems more trouble than its worth when EF decideds to put in these default values.
Has anyone found out the answer to this? Entity Framework Code First is absolutely ridicously in not allowing me to set a default value. Having an audit column like created date is one of the most common db requirements in the world. It should be easily
supported out of the box and it is clear that it is not.
QuantumInfor...
Member
199 Points
228 Posts
Default value for datetime column in EF5
Dec 27, 2012 01:42 PM|LINK
I'm trying to add a default value to this but for some reason EF5 Stuck one in there already in the table creation even though I didn't specify this. Why did it do it? what is the best way to remove it an add this
public override void Up() { AlterColumn("dbo.tb", "DateCreated", c => c.DateTime(defaultValueSql: "GETDATE()")); }Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Default value for datetime column in EF5
Dec 28, 2012 12:27 AM|LINK
What does this mean?
Can you elebrate it more?
QuantumInfor...
Member
199 Points
228 Posts
Re: Default value for datetime column in EF5
Dec 28, 2012 10:19 AM|LINK
hi mate, basically in sql server I see a defualt value of
DEFAULT ('1900-01-01T00:00:00.000') , I'm not sure how to get rid of it with the fluent api so I can apply my new migration.
CREATE TABLE [dbo].[Investors] ( [Id] INT IDENTITY (1, 1) NOT NULL, [UserId] UNIQUEIDENTIFIER DEFAULT ('00000000-0000-0000-0000-000000000000') NOT NULL, [Name] NVARCHAR (50) DEFAULT ('') NOT NULL, [DateCreated] DATETIME DEFAULT ('1900-01-01T00:00:00.000') NOT NULL, CONSTRAINT [PK_dbo.Investors] PRIMARY KEY CLUSTERED ([Id] ASC) );Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Default value for datetime column in EF5
Dec 29, 2012 12:14 AM|LINK
Remove this statement above and the default value is missing.
QuantumInfor...
Member
199 Points
228 Posts
Re: Default value for datetime column in EF5
Dec 29, 2012 09:21 AM|LINK
thanks, I know I can do that but I wanted to do all the DB mods through the fluent migration, which seems like a best practice since each developer oculd then run his own DB without me having to tell them to do manual stuff.
What do you think?
Mabye in future I shold avoid [required] metadatatags since it seems more trouble than its worth when EF decideds to put in these default values.
bogden
Member
10 Points
19 Posts
Re: Default value for datetime column in EF5
Jan 17, 2013 05:32 PM|LINK
Has anyone found out the answer to this? Entity Framework Code First is absolutely ridicously in not allowing me to set a default value. Having an audit column like created date is one of the most common db requirements in the world. It should be easily supported out of the box and it is clear that it is not.