How to fix Migration issues when it comes to columns not allowing null values

0

After changing the model and making the migration for the Tickets entity, I tried updating the database using Update-Database, Update-Database TicketStatus, and even used the -v extension as well to fix the issues I was having.

When trying to update the database I got an error about Status not being able to access null values. I then used the Required decorator in order to make sure Status wouldn't be null but there are still errors being thrown.

I also tried making a change to the Employee entity (uses identity authentification) as well and the migration worked. But when trying to update the database, the same status error was being displayed.

https://github.com/zhadjah9559/HelpDeskTicket/tree/3.LoginAndDB

Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'Status', table 'aspnet-HelpDeskTicket-9D2F91E0-D7B7-410E-8123-BA93C7E02205.dbo.Tickets'; column does not allow nulls. UPDATE fails.

c#
sql-server
visual-studio
asp.net-core
migration
asked on Stack Overflow Oct 27, 2020 by Darnell • edited Oct 27, 2020 by Rufus L

1 Answer

0

Check your migration file and add a default value to the Status column

migrationBuilder.AddColumn<[Your Column Type]>(
            name: "Status",
            table: "Tabe name",
            type: "t",
            nullable: false,
            defaultValue: true);
answered on Stack Overflow Oct 27, 2020 by eldu_gate • edited Oct 27, 2020 by Dale K

User contributions licensed under CC BY-SA 3.0