Newly Added DB Columns Are Not Recognized.

Topics: Customizing Orchard
Nov 8, 2011 at 11:07 PM

Hi There,

I have a model which extends ContentPartRecord and ContentPart<T>, It was working well until, I added a few more properties to this model. I also added columns in Migrations file corresponding to those new properties. I then started getting:

[SqlException (0x80131904): Invalid column name '<column>' for all the newly added columns.

What could this be?

Thanks in advance for your assistance.

~Steve

Coordinator
Nov 8, 2011 at 11:19 PM

You don't add the columns to the create method, you add a new UpdateFromXXX method that does a table alteration.

Nov 9, 2011 at 2:28 PM

Thanks Bertrand.

Nov 9, 2011 at 5:48 PM

Hi Bertrand,

I have added the UpdateFrom<PreviousVersion> method to the migrations class as you recommended. But I am still getting the invalid column name exception.

Is there another remedy that I can apply or maybe something I am perhaps missing?

 

Thanks.

 

~Steve

Nov 9, 2011 at 6:01 PM

Hi Bertrand,

I have added the UpdateFrom<PreviousVersion> method to the migrations class as you recommended. But I am still getting the invalid column name exception.

Also my migration currently looks something like this:

public class Migrations : DataMigrationImpl {
         public int Create() {
            SchemaBuilder.CreateTable("MyPartRecord", table => table
                .ContentPartRecord()

                .Column("Column1", DbType.String)

            );


            ContentDefinitionManager.AlterPartDefinition(
                typeof(MyPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("MyWidget", cfg => cfg
                .WithPart("DetailedQuotePart")
                .WithPart("WidgetPart")
                .WithPart("CommonPart")
                .WithSetting("Stereotype", "Widget"));
           

            return 1;
        }

      public int UpdateFrom1() {
            SchemaBuilder.AlterTable("MyPartRecord", table => table
                .AddColumn("Column2", DbType.Int16));

           SchemaBuilder.AlterTable("MyPartRecord", table => table
                .AddColumn("Column3", DbType.Int16));

          
            return 2;
        }


 

 

Is there another remedy that I can apply or maybe something I am perhaps missing?

 

Thanks.

 

~Steve

Coordinator
Nov 9, 2011 at 6:07 PM

And you did upgrade the feature from the dashboard? Look into the database and check to see what that table's schema looks like.

Nov 9, 2011 at 6:14 PM

Thanks Bertrand,

I was inadvertently skipping the update location when I enter the add widget url directly to the browser.

I have found the update location, upgraded the widget, and it works properly now.

Thanks again.

~Steve