In fluentMigrator, is it possible to set a column default to a function?
Specifically, I'm adding a uniqueidentifier (Guid) column to a SQL Server 2008 table that already contains data, and it's going to be a required field - is it possible to set the default to the NewId() function?
Changing a Column's Default Value. To set a new default for a column, use a command like: ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77; Note that this doesn't affect any existing rows in the table, it just changes the default for future INSERT commands.
The DEFAULT constraint is used to set a default value for a column. The default value will be added to all new records, if no other value is specified.
Field defaults for NewId() and GetDate() are available (for SQL Server at least) by referring to either SystemMethods.NewGuid
or SystemMethods.CurrentDateTime
, for example:
Create
.Column("incomeIdGuid").OnTable("tblIncome")
.AsGuid()
.NotNullable()
.WithDefaultValue(SystemMethods.NewGuid);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With