Help with error log. 2 Modules throwing errors.

Topics: Administration, Troubleshooting
Feb 5 at 2:14 PM
Hello everyone,

I deleted Taxonomies and Workflows modules by accident. I went back to my 1.9.2 copy of orchard and copied in the folders back into the deployed orchard folder in wwroot. When I restarted orchard everything came back up but the content or layout part of every page. I then just restored the entire Module folder and everything came back to what it should be except.... Taxonomies and Workflows says Out of Date please update and when I click update I get a 404. It appears that these two modules work though if I were to configure them on the back end. Anyway I want to resolve this issue because I believe I messed up the database. Can anyone have a look?

2016-02-05 08:14:36,929 [7] Orchard.Data.Migration.DataMigrationManager - (null) - Error while running migration version 0 for Orchard.Workflows.
(null)
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.SqlClient.SqlException: There is already an object named 'Orchard_Workflows_TransitionRecord' in the database.
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(TaskCompletionSource
1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.RunPendingStatements() in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 337
at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(CreateTableCommand command) in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 92
at Orchard.Data.Migration.Schema.SchemaBuilder.CreateTable(String name, Action1 table) in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 44
at Orchard.Workflows.Migrations.Create()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Orchard.Data.Migration.DataMigrationManager.Update(String feature) in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\DataMigrationManager.cs:line 119
2016-02-05 08:14:37,070 [7] Orchard.Data.Migration.AutomaticDataMigrations - (null) - Could not run migrations automatically on Orchard.Workflows
(null)
2016-02-05 08:14:37,070 [7] Orchard.Data.Migration.AutomaticDataMigrations - (null) - Could not run migrations automatically on Orchard.Taxonomies
(null)
2016-02-05 08:17:19,312 [32] Orchard.Data.Migration.DataMigrationManager - (null) - Error while running migration version 0 for Orchard.Taxonomies.
http://merlin/Admin/Modules/Features
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.SqlClient.SqlException: There is already an object named 'Orchard_Taxonomies_TaxonomyPartRecord' in the database.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 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 z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 337
at Orchard.Data.Migration.Interpreters.DefaultDataMigrationInterpreter.Visit(CreateTableCommand command) in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\Interpreters\DefaultDataMigrationInterpreter.cs:line 92
at Orchard.Data.Migration.Schema.SchemaBuilder.CreateTable(String name, Action
1 table) in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\Schema\SchemaBuilder.cs:line 44
at Orchard.Taxonomies.Migrations.Create()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Orchard.Data.Migration.DataMigrationManager.Update(String feature) in z:\Builds\work\9f6cd39ff0f68f41\src\Orchard\Data\Migration\DataMigrationManager.cs:line 119
2016-02-05 08:19:27,882 [12] NHibernate.Transaction.AdoTransaction - (null) - Begin transaction failed
Developer
Feb 5 at 11:31 PM
So basically what happens here is that your database thinks the migrations version of the Workflows module is behind, so it executes its migrations, which tries to create a table that already exists. To fix this, you need to update a record in a database table called something like Orchard_DataMigrationRecord. Look up the record for the Workflow DataMigrations type, and update its Version column value to the last version number that is returned by the actual DataMigration class in the Workflows module.
Then recycle the application pool (or delete hrestart.txt in the App_Data folder to recycle the shells and their caches), and see what gives. If you're seeing different but similar errors (where a database table already exists), repeat the process for that module.
Feb 8 at 7:48 PM
sfmskywalker wrote:
So basically what happens here is that your database thinks the migrations version of the Workflows module is behind, so it executes its migrations, which tries to create a table that already exists. To fix this, you need to update a record in a database table called something like Orchard_DataMigrationRecord. Look up the record for the Workflow DataMigrations type, and update its Version column value to the last version number that is returned by the actual DataMigration class in the Workflows module.
Then recycle the application pool (or delete hrestart.txt in the App_Data folder to recycle the shells and their caches), and see what gives. If you're seeing different but similar errors (where a database table already exists), repeat the process for that module.
@sfmskywalker

So I am poking around the SQL database and seem to be on the right path.. How do I find the "last version number that is returned by the actual DataMigration class in the Workflows module." Is it under that Migrations.cs file under the module? This is what I see in that file. Any further insight would be amazing! Thanks!

using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;

namespace Orchard.Taxonomies {
public class Migrations : DataMigrationImpl {

    public int Create() {
        SchemaBuilder.CreateTable("TaxonomyPartRecord", table => table
            .ContentPartRecord()
            .Column<string>("TermTypeName", column => column.WithLength(255))
            .Column<bool>("IsInternal")
        );

        SchemaBuilder.CreateTable("TermPartRecord", table => table
            .ContentPartRecord()
            .Column<string>("Path", column => column.WithLength(255))
            .Column<int>("TaxonomyId")
            .Column<int>("Count")
            .Column<int>("Weight")
            .Column<bool>("Selectable")
        ).AlterTable("TermPartRecord", table => table
            .CreateIndex("IDX_Path", "Path")
        );

        SchemaBuilder.CreateTable("TermContentItem", table => table
            .Column<int>("Id", column => column.PrimaryKey().Identity())
            .Column<string>("Field", column => column.WithLength(50))
            .Column<int>("TermRecord_id")
            .Column<int>("TermsPartRecord_id")
        );

        ContentDefinitionManager.AlterTypeDefinition("Taxonomy", cfg => cfg
            .WithPart("TaxonomyPart")
            .WithPart("CommonPart")
            .WithPart("TitlePart")
            .WithPart("AutoroutePart", builder => builder
            .WithSetting("AutorouteSettings.AllowCustomPattern", "True")
            .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
            .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]")
            .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
        );

        SchemaBuilder.CreateTable("TermsPartRecord", table => table
            .ContentPartRecord()
        );

        ContentDefinitionManager.AlterTypeDefinition("TaxonomyNavigationMenuItem",
           cfg => cfg
               .WithPart("TaxonomyNavigationPart")
               .WithPart("MenuPart")
               .WithPart("CommonPart")
               .DisplayedAs("Taxonomy Link")
               .WithSetting("Description", "Injects menu items from a Taxonomy")
               .WithSetting("Stereotype", "MenuItem")
           );

        return 4;
    }

    public int UpdateFrom1() {
        ContentDefinitionManager.AlterTypeDefinition("TaxonomyNavigationMenuItem",
           cfg => cfg
               .WithPart("TaxonomyNavigationPart")
               .WithPart("MenuPart")
               .WithPart("CommonPart")
               .DisplayedAs("Taxonomy Link")
               .WithSetting("Description", "Injects menu items from a Taxonomy")
               .WithSetting("Stereotype", "MenuItem")
           );

        return 3;
    }

    public int UpdateFrom3() {
        SchemaBuilder.AlterTable("TermPartRecord", table => table
            .CreateIndex("IDX_Path", "Path")
        );

        return 4;
    }
}
}