5

Using orchad 1.6 in the migration file I have just altered a table and added a column. I need this column to be NotNull, but it doesnt allow you to alter a table enter a NotNull type, so i've used Nullable and entered data into the existing columns.

I then want to edit this column and change it to a Nullable, but am unsure how....

public int UpdateFrom37()
        {
            SchemaBuilder.AlterTable("ManufacturedProductOrders", table => table
                .AddColumn<DateTime>("DateOrdered", c => c.Nullable())
                );

            return 38;
        }

        public int UpdateFrom38()
        {
            SchemaBuilder.AlterTable("ManufacturedProductOrders", table => table
                .AlterColumn("DateOrdered", c => c.WithType(dbType.???????????
                );
        }
John
  • 3,965
  • 21
  • 77
  • 163

1 Answers1

5

I guess you want to change from NULL to NOT NULL, right? The code above clearly states that you already have a nullable column.

AlterColumn command does not currently allow changing column 'nullability'.

Your best option is to issue a manual ALTER TABLE command through SchemaBuilder.ExecuteSql() or directly in the database. You can read about it eg. here.

Community
  • 1
  • 1
Piotr Szmyd
  • 13,371
  • 6
  • 44
  • 61
  • Is it necessary to use ExecuteSql() ? There's an AlterTable() method, why shouldn't that be the recommended solution? I'm not very experienced with Orchard, so I don't quite understand. Thanks! – Danny Bullis Mar 02 '15 at 21:41