Question

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.???????????
                );
        }
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top