This project is read-only.

Migration not running

Topics: Customizing Orchard
May 14, 2013 at 4:18 AM
Edited May 14, 2013 at 6:21 AM
Hi, newbie question here. Using Orchard 1.6 I've created my module via the command prompt with:
feature enable Orchard.CodeGeneration
codegen module CV.Prototype
codegen datamigration CV.Prototype
And below is my Migration.cs:
using System;
using System.Collections.Generic;
using System.Data;
using CV.Prototype.Models;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data;
using Orchard.Data.Migration;

namespace CV.Prototype
    public class Migrations : DataMigrationImpl

        private readonly IRepository<ProductRecord> _productRepository;

        public Migrations(IRepository<ProductRecord> productRepository)
            _productRepository = productRepository;

        public int CreateInitial() {
            ContentDefinitionManager.AlterTypeDefinition("Category", builder =>
            return 1;


        public int Create1()
            ContentDefinitionManager.AlterTypeDefinition("Category", builder => builder
                .WithPart("BodyPart", partBuilder =>
                partBuilder.WithSetting("BodyTypePartSettings.Flavor", "text"))
                .WithPart("AutoroutePart", partBuilder =>
                partBuilder.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
                .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
                .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Category Title', Pattern: 'category/{Content.Slug}', Description: 'category/category-title'}]")
                .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")));

            SchemaBuilder.CreateTable("CategoryRecord", table =>
                .Column<int>("Id", col => col.PrimaryKey().Identity())

            SchemaBuilder.CreateTable("ProductRecord", table =>
                .Column<int>("Id", col => col.PrimaryKey().Identity())

            SchemaBuilder.CreateTable("CategoryProductRecord", table =>
                .Column<int>("Id", col => col.PrimaryKey().Identity())

            _productRepository.Create(new ProductRecord { Name = "Product 1" });
            _productRepository.Create(new ProductRecord { Name = "Product 2" });
            _productRepository.Create(new ProductRecord { Name = "Product 3" });
            _productRepository.Create(new ProductRecord { Name = "Product 4" });
            _productRepository.Create(new ProductRecord { Name = "Product 5" });
            _productRepository.Create(new ProductRecord { Name = "Product 6" });
            _productRepository.Create(new ProductRecord { Name = "Product 7" });

            return 2;
When I enabled the CV.Prototype module I expected it to hit a breakpoint or at least create the appropriate row in the Orchard_Framework_DataMigrationRecord table, but nothing it happening. What might I have missed?

Edit: I've got the Movies module enabled too, and have added:
        public int UpdateFrom10()
//Do nothing 
            return 11;
In the DataMigrationRecord table that is not being updated either.

Edit 2: Some more information that may help. The auto-compile does not appear to be working either. In the ActorsAdmin controller in the Movies module I changed the GetActorTableShape action to OrderByDescending, and when I reload the order is unchanged. When I then build the solution the order of the actors is reversed, as it should be.
May 14, 2013 at 10:58 AM
I can't see what would call either your methods CreateInitial & Create1

The documentation I've always followed (and works for me) uses
public int Create()
    /* Do some funky migration stuff */

    return 1;

public int UpdateFrom1()
   /* Do some more funky migration stuff */

   return 2;
See the section Creating the Initial Data Migration File within this document Creating a module with a simple text editor
May 15, 2013 at 4:32 AM
OK, I've got it working now, the Migration at least.

It appears the method MUST follow the form:

Now I need to figure out why the auto-compile doesn't work. Any clues on that one would be appreciated!
May 15, 2013 at 7:48 AM
Do you get anything in the logs?

May 15, 2013 at 7:56 AM
For the migration issues, yes, the log files pointed me to the right place. Since I've fixed that, the files orchard-debug-2013.05.15.log and orchard-error-2013.05.15.log exist, but they are empty.

I'll post another topic about the lack of auto-compile. Thanks for your guidance Alan, the learning curve is steep for Orchard!
May 15, 2013 at 8:42 AM
You may have already seen it, but aside from the project documentation I found this pdf a good learning resource

Orchard CMS: Up and Running