bubibubi / JetEntityFrameworkProvider

Microsoft Access (Jet) Entity Framework provider
89 stars 26 forks source link

Migration does not mark column as nullable #16

Open erikvdv1 opened 7 years ago

erikvdv1 commented 7 years ago

When changing the type of a column from int to int? the migration below is generated, however when I apply the migration the column is not marked as nullable (i.e. is still marked as required in Access). If I create an initial migration it does create the column with the correct settings.

public partial class MakeNullable : DbMigration
    {
        public override void Up()
        {
            AlterColumn("dbo.Items", "SomeProp", c => c.Int());
        }

        public override void Down()
        {
            AlterColumn("dbo.Items", "SomeProp", c => c.Int(nullable: false));
        }
    }
bubibubi commented 7 years ago

In your code Up is setting the column to nullable, Down to not nullable. After Up the column should be nullable.

I'm running this tests

CreateTable(
        "MigrationMakeNullableInt",
        c => new
        {
            Id = c.Int(nullable: false, identity: true),
            Counter = c.Int(nullable: true)
        })
    .PrimaryKey(t => t.Id);

AlterColumn("dbo.MigrationMakeNullableInt", "Counter", c => c.Int(nullable: false));

These are the DDL statements generated by provider

CREATE TABLE [MigrationMakeNullableInt] (
 [Id] int not null identity(1,1)
, [Counter] int null
);
ALTER TABLE [MigrationMakeNullableInt] ADD CONSTRAINT [PK_MigrationMakeNullableInt_8805946a] PRIMARY KEY ([Id]);
ALTER TABLE [MigrationMakeNullableInt] ALTER COLUMN [Counter] int not null;

At the end the table has the Counter column set to null.

Probably the problem is different. Do you have values in every record?

erikvdv1 commented 7 years ago

I've tested it with an empty table and with a table with records. The records have values because the column is non-nullable. The issue remains in both scenarios.

The issue occurs only when migrating an existing database. If the database is created from scratch (even with multiple migrations in a row) all is fine.