Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • john blair 48 posts 219 karma points
    Jan 19, 2020 @ 18:58
    john blair
    0

    How to add a migration that adds a boolean column to an existing table, is not null and has a default value of false?

    I tried this

     public override void Migrate()
        {
            Alter.Table(DatabaseConstants.QuestionTable).AddColumn(DatabaseConstants.UnpublishedColumn).AsBoolean().NotNullable().WithDefaultValue(false);
    
        }
    

    but I get the obscure error The migration has run, but leaves an expression that has not run.

    Umbraco fails to boot - i have tried replacing the value with 0 instead of false - same error.

    What is the correct way of doing this in Umbraco 8?

  • Abilash Ashok 63 posts 418 karma points
    Feb 12, 2020 @ 11:07
    Abilash Ashok
    0

    Hello, were you able to solve this problem? I am also facing this issue. Thanks.

  • Abilash Ashok 63 posts 418 karma points
    Feb 12, 2020 @ 11:15
    Abilash Ashok
    0

    Hey, I fixed it. We need to add Do() at the end of the statement as below:

    Alter.Table(DatabaseConstants.QuestionTable).AddColumn(DatabaseConstants.UnpublishedColumn).AsBoolean().NotNullable().WithDefaultValue(false).Do();

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft