1

Closed

Code first migrations fails to modify from not-null to nullable

description

Using EntityFramework for sql server compact 6.0.2 (and sql server compact 4.0) with both Automatic Migrations set to true, and with explicit migrations (and Automatic Migrations set to false), the underlying database fails to update an int (nullable:false) to a nullable int.

This results in an error when the database is next appended with a record containing a null value in the modified field.

using explicit migrations add-migration works perfectly - ie:
public partial class InitialTrialData : DbMigration
{
    public override void Up()
    {
        CreateTable(
            "dbo.Participants",
            c => new
                {
                    BlockNumber = c.Int(nullable: false)

public partial class TrialDataV2 : DbMigration
{
    public override void Up()
    {
         AlterColumn("dbo.Participants", "BlockNumber", c => c.Int())
and when update-database is called, no error is generated:
-Applying explicit migration: 201403100345554_TrialDataV2.

however, when querying the database with SQL Server Compact Toolbox, the column is still Int NOT NULL

At the moment workaround is to execute SQL method:
    public override void Up()
    {
        Sql("ALTER TABLE [Participants] ALTER COLUMN [BlockNumber] INTEGER NULL;");
but the developer has to track down the error first.

comments

moozzyk wrote Mar 10 at 7:14 AM

RoMiller wrote Mar 10 at 7:04 PM

Hey Jacob, can you verify that this is a dupe and is fixed in 6.1

jemartti wrote Apr 10 at 1:00 AM

This does appear to be a dupe of 1852. I was able to reproduce in 6.0.2, but it looks like it's working in 6.1.0.

mgirgin wrote Apr 11 at 7:37 PM

EF Team Triage: Closing as Dupe of 1852. Please upgrade to 6.1 for a fix.