This project is read-only.

Migrations not working

Topics: Writing modules
Oct 17, 2012 at 8:08 PM

I created a new widget. First migrations are ran and in the UpdateFrom2 method I want to change the table like

public int UpdateFrom2() {
    SchemaBuilder.AlterTable("MapRecord", table => table
        .AddColumn("Width", DbType.Int32)
        .AddColumn("Height", DbType.Int32)

    return 3;

However if I refresh my site and take a look at the database the 2 columns don't get added. Worse of all, my widget doesn't display itself anymore even though I only added 2 properties to the Record and the Model classes. I didn't update the views yet.


Oct 17, 2012 at 8:35 PM

Logs, Logs, Logs ;)


Oct 17, 2012 at 8:43 PM
Edited Oct 17, 2012 at 9:14 PM

I tried setting the log4net to error, debug, ... possibilities. Either I don't get anything or I get a load of information which is not comprehensible. Which setting is best to discover what's going wrong?

Or is there a certain keyword on which I can search in the log?

Oct 17, 2012 at 9:27 PM

In the logs, put on ALL, I can see the following:

Orchard.Environment.Extensions.Loaders.DynamicExtensionLoader - ExtensionActivated: Module "Maps" has changed, forcing AppDomain restart

Is that the one I'm after? If so why doesn't it migrate to the latest version? This is really odd.

Oct 17, 2012 at 9:40 PM

No. Your migration must have failed for some reason. If you can, delete your database, start over and put a breakpiont in that migration. Otherwise, roll back migration version number for your module in the relevant table, then put a breakpoint.

Oct 17, 2012 at 9:54 PM
bertrandleroy wrote:

in the relevant table, then put a breakpoint.

I don't think I can hit breakpoints in webmatrix 2.

The relevant table, do you mean Orchard_Framework_DataMigrationRecord? Or something else?

Oct 17, 2012 at 10:10 PM

No, you can't, so you'd have to resort to more artisanal debugging methods. Yes, that's the table.

Oct 17, 2012 at 10:12 PM

Ok. I started out from scratch. Renamed a couple of classes in my new experiment to be able to search better on it. The migrations work right now which is great. However the views don't get shown anymore. In the Widgets menu I can add the widget to a zone and it gives the message "Your My Maps Record" has been added. However it doesn't show up on the layer overview nor on the page.

Instead of Map I used MyMaps this time everywhere in the naming, also altered the names in the drivers to

protected override DriverResult Display(MyMapsPart part, string displayType, dynamic shapeHelper)
    return ContentShape("Parts_MyMaps", () => shapeHelper.Parts_MyMaps(
        Longitude: part.Longitude,
        Latitude: part.Latitude,
        ZoomLevel: part.ZoomLevel

// Get
protected override DriverResult Editor(MyMapsPart part, dynamic shapeHelper)
    return ContentShape("Parts_MyMaps_Edit",
        () => shapeHelper.EditorTemplate(
            TemplateName: "Parts/MyMaps",
            Model: part,
            Prefix: Prefix));

// Post
protected override DriverResult Editor(MyMapsPart part, IUpdateModel updater, dynamic shapeHelper)
    updater.TryUpdateModel(part, Prefix, null, null);
    return Editor(part, shapeHelper);

where both views are in Parts/MyMaps.cshtml.


Oct 17, 2012 at 10:39 PM

Okay so a few requirements for a Part...

1. A Driver (Which you have)

2. A Handler - This will setup repository stuff.. plus lots of other juicy things.

3. - Make sure you have a <Place Parts_MyMaps_Edit="Content:1"/> in there (Without this... It wont display)


Oct 18, 2012 at 7:23 AM

If I add the file it shows the input fields of the widget when adding it to a zone so that's progress:

  <Place Parts_MyMaps="Content:1"/>
  <Place Parts_MyMaps_Edit="Content:7.5"/>

However after saving it I still get the ok message that it's been added but I don't see it being added in the layers and it's also not visible on the pages. Little babysteps here. Thanks for the help!

Oct 18, 2012 at 8:52 AM
Edited Oct 18, 2012 at 9:55 AM

Something else. I get the following error in the log:

NHibernate.Exceptions.GenericADOException: could not insert: [MyMaps.Models.MyMapsRecord#15]

[SQL: INSERT INTO MyMaps_MyMapsRecord (Latitude, Longitude, ZoomLevel, Width, Height, Description, Id) VALUES (?, ?, ?, ?, ?, ?, ?)]

---> System.Data.SqlServerCe.SqlCeException: The column name is not valid. [ Node name (if any) = ,Column name = Id ]

And when I take a look in the database then indeed the Id column isn't there. How come as I inherited from ContentPartRecord?

    public class MyMapsRecord : ContentPartRecord
        public virtual double Latitude { get; set; }
        public virtual double Longitude { get; set; }
        public virtual int ZoomLevel { get; set; }
        public virtual int Width { get; set; }
        public virtual int Height { get; set; }
        public virtual string Description { get; set; }

    public class MyMapsPart : ContentPart<MyMapsRecord>
        public double Latitude
            get { return Record.Latitude; }
            set { Record.Latitude = value; }

        public double Longitude
            get { return Record.Longitude; }
            set { Record.Longitude = value; }

        public int ZoomLevel
            get { return Record.ZoomLevel; }
            set { Record.ZoomLevel = value; }

        public int Width
            get { return Record.Width; }
            set { Record.Width = value; }

        public int Height
            get { return Record.Height; }
            set { Record.Height = value; }

        public string Description
            get { return Record.Description; }
            set { Record.Description = value; }

Update: when I add the Id column myself then everything works out as expected. Any pointers?

Oct 18, 2012 at 6:02 PM

You probably forgot to .ContentPartRecord() the table in the migration.

Oct 18, 2012 at 9:23 PM
bertrandleroy wrote:

You probably forgot to .ContentPartRecord() the table in the migration.

yes, that seemed to be the culprit. Sigh. Thanks for bearing with me man.

I was trying to fiddle around myself and try out to make something like which was provided by that hands on labs that I found at