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.38k stars 1.12k forks source link

Cannot alter table default in migration #4183

Open orchardbot opened 10 years ago

orchardbot commented 10 years ago

MpDzik created: https://orchard.codeplex.com/workitem/20354

The following code fails in a migration: SchemaBuilder.AlterTable("MyTable", table => table .AlterColumn("MyColumn", c => c.WithDefault("MyColumn")));

The table previously had a default value, but the migration was supposed to change it. I get the following exception: System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'set'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.RunPendingStatements() in c:\Axess\Bridge\orchard\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 336 at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(AlterTableCommand command) in c:\Axess\Bridge\orchard\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 141 at Orchard.Data.Migration.Interpreters.AbstractDataMigrationInterpreter.Visit(ISchemaBuilderCommand command) in c:\Axess\Bridge\orchard\src\Orchard\Data\Migration\Interpreters\AbstractDataMigrationInterpreter.cs:line 17 at Orchard.Data.Migration.Schema.SchemaBuilder.Run(ISchemaBuilderCommand command) in c:\Axess\Bridge\orchard\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 58 at Orchard.Data.Migration.Schema.SchemaBuilder.AlterTable(String name, Action`1 table) in c:\Axess\Bridge\orchard\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 38 at Axbit.Search.Migrations.UpdateFrom5()

orchardbot commented 10 years ago

@csurieux commented:

Similar to this one and severalothers related to Default not working with SQL Server https://orchard.codeplex.com/workitem/19298