1

I am using code similar to the following:

 Database.AddColumn(
             "TableName",
             new Column(
                        "ColumnName",
                        DbType.String,
                        ColumnProperty.NotNull,
                        "TypeName"));

But I am getting error as "TypeName" is not allowed in this context, allowed context are constants, constants expression but no column name.

Avinash
  • 173
  • 1
  • 4
  • 17
  • What is the definition of `ColumnName`? `Migrator.Framework.Column` does have a constructor which accepts `string, DbType, ColumnProperty, object` – The Scrum Meister Feb 11 '11 at 06:46
  • Here ColumnName is just a string, i am getting complain on Default value which i am providing as string. – Avinash Feb 11 '11 at 07:21

2 Answers2

2

For strings, you have to put single quotes around the default value as the ALTER statement is built with it directly. Try this:

Database.AddColumn(
         "TableName",
         new Column(
                    "ColumnName",
                    DbType.String,
                    ColumnProperty.NotNull,
                    "'TypeName'"));
Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
0

Have you tried this way?

Database.AddColumn("table", new Column("colName", DbType.String, "defaultValue"));
danyolgiax
  • 12,798
  • 10
  • 65
  • 116