4
Vote

AlterColumn and WithDefault not saving default value

description

When trying to add a default value to an existing column, the default value is not saved.

This is what I have in migrations:

SchemaBuilder.AlterTable("RealEstatePartRecord", cfg => cfg.AlterColumn("datecolumn1", r => r.WithDefault(DateTime.Now)));

This code generates the following SQL Statement, which cannot be parsed:

alter table [RealEstate_RealEstatePartRecord] alter column [datecolumn1] set default '11/23/2012 16:50:50'

The exception given is as follows:

System.Data.SqlClient.SqlException was unhandled by user code
Message=Incorrect syntax near the keyword 'set'.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=15
LineNumber=1
Number=156
Procedure=""
Server=localhost\ROB
State=1
StackTrace:
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.RunPendingStatements() in C:\projects\local\VerbruggeOrchard2\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 347
   at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(AlterTableCommand command) in C:\projects\local\VerbruggeOrchard2\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 142
   at Orchard.Data.Migration.Interpreters.AbstractDataMigrationInterpreter.Visit(ISchemaBuilderCommand command) in C:\projects\local\VerbruggeOrchard2\src\Orchard\Data\Migration\Interpreters\AbstractDataMigrationInterpreter.cs:line 17
   at Orchard.Data.Migration.Schema.SchemaBuilder.Run(ISchemaBuilderCommand command) in C:\projects\local\VerbruggeOrchard2\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 46
   at Orchard.Data.Migration.Schema.SchemaBuilder.AlterTable(String name, Action`1 table) in C:\projects\local\VerbruggeOrchard2\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 26
   at RealEstate.Migration.UpdateFrom5()
InnerException:

The SQL it would have to generate in order to save the default value would look something like this:

alter table "RealEstatePartRecord" add constraint DF_1 default ('11/23/2012 16:50:50') for "datecolumn1"

comments