Could not run migrations automatically on x

Topics: Troubleshooting, Writing modules
Mar 18, 2012 at 2:51 PM

I've updated my module NogginBox.BingMapLists to work in 1.4, but when I try to migrate my 1.3 site to 1.4 the automatica migrations blow the whole site up while trying to update my MapList data. I think it may have something to do with the 1-n relationship between content parts in my module.

Here is the error from the log:

2012-03-18 14:19:24,580 [6] Orchard.Exceptions.DefaultExceptionPolicy - Exception has been thrown by the target of an invocation.
2012-03-18 14:19:39,179 [6] Orchard.Data.Migration.AutomaticDataMigrations - Could not run migrations automatically on NogginBox.BingMapList
2012-03-18 14:19:42,767 [6] Orchard.Data.Migration.DataMigrationManager - An unexpected error orccured while applying migration on Containers from version 2
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.SqlClient.SqlException: There is already an object named 'NogginBox_BingMapList_BingLocationRecord' in the database.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.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:\Users\NogginBox\Orchard1.4.full\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 346
   at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(AlterTableCommand command) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 135
   at Orchard.Data.Migration.Interpreters.AbstractDataMigrationInterpreter.Visit(ISchemaBuilderCommand command) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Data\Migration\Interpreters\AbstractDataMigrationInterpreter.cs:line 17
   at Orchard.Data.Migration.Schema.SchemaBuilder.Run(ISchemaBuilderCommand command) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 46
   at Orchard.Data.Migration.Schema.SchemaBuilder.AlterTable(String name, Action`1 table) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 26
   at Orchard.Core.Containers.Migrations.UpdateFrom2() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard.Web\Core\Containers\Migrations.cs:line 62
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Orchard.Data.Migration.DataMigrationManager.Update(String feature) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Data\Migration\DataMigrationManager.cs:line 105
2012-03-18 14:19:42,799 [6] Orchard.Data.Migration.AutomaticDataMigrations - Could not run migrations automatically on Containers
2012-03-18 14:19:42,861 [5] Orchard.Tasks.BackgroundService - Error while processing background task
NHibernate.QueryException: could not resolve property: TitlePartRecord of: Orchard.ContentManagement.Records.ContentItemVersionRecord
   at NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName)
   at NHibernate.Persister.Entity.AbstractEntityPersister.ToType(String propertyName)
   at NHibernate.Loader.Criteria.EntityCriteriaInfoProvider.GetType(String relativePath)
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetPathInfo(String path)
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateCriteriaEntityNameMap()
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor(ISessionFactoryImplementor factory, CriteriaImpl criteria, String rootEntityName, String rootSQLAlias)
   at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters)
   at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
   at NHibernate.Impl.CriteriaImpl.List(IList results)
   at NHibernate.Impl.CriteriaImpl.List[T]()
   at Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 146
   at Orchard.ContentManagement.DefaultContentQuery.ContentQuery`1.Orchard.ContentManagement.IContentQuery.List() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 191
   at Orchard.Blogs.Services.BlogService.Get(VersionOptions versionOptions)
   at Orchard.Blogs.Services.BlogService.Get()
   at Orchard.Blogs.Routing.BlogPathConstraintUpdator.Refresh()
   at Orchard.Blogs.Routing.BlogPathConstraintUpdator.Orchard.Tasks.IBackgroundTask.Sweep()
   at Orchard.Tasks.BackgroundService.Sweep() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Tasks\BackgroundService.cs:line 31
2012-03-18 14:19:43,112 [6] NHibernate.AdoNet.AbstractBatcher - Could not execute command: UPDATE Orchard_Comments_CommentPartRecord SET CommentsPartRecord_Id = @p0 WHERE Id = @p1
System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'CommentsPartRecord_Id'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.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.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
2012-03-18 14:19:43,158 [6] NHibernate.Util.ADOExceptionReporter - Invalid column name 'CommentsPartRecord_Id'.
2012-03-18 14:19:43,180 [6] NHibernate.Event.Default.AbstractFlushingEventListener - Could not synchronize database state with session
NHibernate.Exceptions.GenericADOException: could not insert collection rows: [Orchard.Comments.Models.CommentsPartRecord.CommentPartRecords#15][SQL: UPDATE Orchard_Comments_CommentPartRecord SET CommentsPartRecord_Id = @p0 WHERE Id = @p1] ---> System.Data.SqlClient.SqlException: Invalid column name 'CommentsPartRecord_Id'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.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.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
   at NHibernate.Persister.Collection.AbstractCollectionPersister.PerformInsert(Object ownerId, IPersistentCollection collection, IExpectation expectation, Object entry, Int32 index, Boolean useBatch, Boolean callable, ISessionImplementor session)
   at NHibernate.Persister.Collection.AbstractCollectionPersister.InsertRows(IPersistentCollection collection, Object id, ISessionImplementor session)
   --- End of inner exception stack trace ---
   at NHibernate.Persister.Collection.AbstractCollectionPersister.InsertRows(IPersistentCollection collection, Object id, ISessionImplementor session)
   at NHibernate.Action.CollectionUpdateAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
2012-03-18 14:19:43,254 [6] NHibernate.Impl.AbstractSessionImpl - DTC transaction prepre phase failed
NHibernate.Exceptions.GenericADOException: could not insert collection rows: [Orchard.Comments.Models.CommentsPartRecord.CommentPartRecords#15][SQL: UPDATE Orchard_Comments_CommentPartRecord SET CommentsPartRecord_Id = @p0 WHERE Id = @p1] ---> System.Data.SqlClient.SqlException: Invalid column name 'CommentsPartRecord_Id'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.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.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
   at NHibernate.Persister.Collection.AbstractCollectionPersister.PerformInsert(Object ownerId, IPersistentCollection collection, IExpectation expectation, Object entry, Int32 index, Boolean useBatch, Boolean callable, ISessionImplementor session)
   at NHibernate.Persister.Collection.AbstractCollectionPersister.InsertRows(IPersistentCollection collection, Object id, ISessionImplementor session)
   --- End of inner exception stack trace ---
   at NHibernate.Persister.Collection.AbstractCollectionPersister.InsertRows(IPersistentCollection collection, Object id, ISessionImplementor session)
   at NHibernate.Action.CollectionUpdateAction.Execute()
   at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
   at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
   at NHibernate.Engine.ActionQueue.ExecuteActions()
   at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
   at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
   at NHibernate.Impl.SessionImpl.Flush()
   at NHibernate.Transaction.AdoNetWithDistrubtedTransactionFactory.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
2012-03-18 14:20:37,400 [11] Orchard.Tasks.BackgroundService - Error while processing background task
NHibernate.QueryException: could not resolve property: TitlePartRecord of: Orchard.ContentManagement.Records.ContentItemVersionRecord
   at NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName)
   at NHibernate.Persister.Entity.AbstractEntityPersister.ToType(String propertyName)
   at NHibernate.Loader.Criteria.EntityCriteriaInfoProvider.GetType(String relativePath)
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetPathInfo(String path)
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateCriteriaEntityNameMap()
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor(ISessionFactoryImplementor factory, CriteriaImpl criteria, String rootEntityName, String rootSQLAlias)
   at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters)
   at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
   at NHibernate.Impl.CriteriaImpl.List(IList results)
   at NHibernate.Impl.CriteriaImpl.List[T]()
   at Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 146
   at Orchard.ContentManagement.DefaultContentQuery.ContentQuery`1.Orchard.ContentManagement.IContentQuery.List() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 191
   at Orchard.Blogs.Services.BlogService.Get(VersionOptions versionOptions)
   at Orchard.Blogs.Services.BlogService.Get()
   at Orchard.Blogs.Routing.BlogPathConstraintUpdator.Refresh()
   at Orchard.Blogs.Routing.BlogPathConstraintUpdator.Orchard.Tasks.IBackgroundTask.Sweep()
   at Orchard.Tasks.BackgroundService.Sweep() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Tasks\BackgroundService.cs:line 31
2012-03-18 14:21:37,407 [12] Orchard.Tasks.BackgroundService - Error while processing background task
NHibernate.QueryException: could not resolve property: TitlePartRecord of: Orchard.ContentManagement.Records.ContentItemVersionRecord
   at NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName)
   at NHibernate.Persister.Entity.AbstractEntityPersister.ToType(String propertyName)
   at NHibernate.Loader.Criteria.EntityCriteriaInfoProvider.GetType(String relativePath)
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetPathInfo(String path)
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator.CreateCriteriaEntityNameMap()
   at NHibernate.Loader.Criteria.CriteriaQueryTranslator..ctor(ISessionFactoryImplementor factory, CriteriaImpl criteria, String rootEntityName, String rootSQLAlias)
   at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary`2 enabledFilters)
   at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
   at NHibernate.Impl.CriteriaImpl.List(IList results)
   at NHibernate.Impl.CriteriaImpl.List[T]()
   at Orchard.ContentManagement.DefaultContentQuery.Slice(Int32 skip, Int32 count) in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 146
   at Orchard.ContentManagement.DefaultContentQuery.ContentQuery`1.Orchard.ContentManagement.IContentQuery.List() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\ContentManagement\DefaultContentQuery.cs:line 191
   at Orchard.Blogs.Services.BlogService.Get(VersionOptions versionOptions)
   at Orchard.Blogs.Services.BlogService.Get()
   at Orchard.Blogs.Routing.BlogPathConstraintUpdator.Refresh()
   at Orchard.Blogs.Routing.BlogPathConstraintUpdator.Orchard.Tasks.IBackgroundTask.Sweep()
   at Orchard.Tasks.BackgroundService.Sweep() in C:\Users\NogginBox\Orchard1.4.full\src\Orchard\Tasks\BackgroundService.cs:line 31

Any ideas what's causing the problem and what I can do to fix it?

Thanks!

Coordinator
Mar 19, 2012 at 8:09 PM

It would help to see your migration code, but it seems like you're attempting to recreate the table whereas it already exists.

Mar 20, 2012 at 11:31 AM

Thanks Bertrand. You're right. I put a break point in my migration and the create method was running again.

Took me a while to figure out why. Turns out  I changed the namespace of my migration a while ago to accuratly reflect the directory it was in (Resharper told me to do it) and this meant it couldn't find the version info in Orchard_Framework_DataMigrationRecord. So it thought it was a new module and was running create again.

On a related note I'm not sure what the best practice is for writing migrations to update to 1.4. when you've used the now defunct routepart in your module. I asked this question where people suggestion you should write code to manually move your route and title data. That seems a bit difficult to implement when there is the autoupdate module.