Orchard and SchemaBuilder AlterTable and AlterColumn
I took a few minutes to update an Orchard Module I use on DavidHayden.me to display various thoughts on my blog. In the Migration.cs file I wanted to change the size of the Note Column from 500 characters to 2000 characters, because I wanted to add HTML to the Note Field for links, etc. I could have made it unlimited, but I didn't want the notes to become like blog posts so I thought 2000 was a fair number to display a thought and include some basic HTML. If you are familiar with altering a table column in Orchard CMS, you know this takes you into the Migration.cs file of the module and the joys of using SchemaBuilder to alter the table and column.
My first attempt to change the string column from 500 characters to 2000 characters was unsuccessful as I figured I could just use the WithLength(2000) with SchemaBuilder.AlterTable to adjust the length of the column. Doing so kept giving me a cryptic error that I must specify the column type when trying to adjust its length. After a little digging it turns out I need to use WithType to adjust the length of the column in the Orchard CMS Table.
In my Orchard Module's Migration.cs file I added the following entry to change the length of the column from 500 to 2000 using SchemaBuilder.AlterTable and AlterColumn:
public int UpdateFrom1() {
SchemaBuilder.AlterTable("NoteRecord", table => table
.AlterColumn("Note", c => c.WithType(DbType.String, 2000))
);
return 2;
}
With this change I now have enough room to put some basic HTML in my Note Field.
I hope you enjoyed this simple tip on using SchemaBuilder.AlterTable and AlterColumn to change the length of a column in Orchard CMS.

