OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

AlterColumn and WithDefault not saving default value #3125

Open orchardbot opened 11 years ago

orchardbot commented 11 years ago

cyphax created: https://orchard.codeplex.com/workitem/19296

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"

orchardbot commented 11 years ago

infofromca commented:

http://orchard.codeplex.com/discussions/359526