My ASP.NET MVC 4 application uses Entity Framework 6 and a database-first approach. It is already in production environment, and now wants to add new column to the Deposit
table and this column is not null. The production table already has a lot of data.
How should I manage this changes, in code-first approach, can anyone help me out? What should I do, I am new to Entity Framework.
If you will continue to use the database-first approach you can do something like that:
1) run a script to migrate DB:
ALTER TABLE Deposit ADD <column_name> INT NULL
GO
UPDATE Deposit SET <a valid not null values for your column>
GO
ALTER TABLE Deposit ALTER COLUMN <column_name> INT NOT NULL
GO
2) Since you are using the db-first approach you need update edmx
model (.edmx
file) which is already attached to db. If I remember correctly, you can do it from context menu in Solution Explorer.