Click here to Skip to main content
15,909,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am a beginner for MVC framework.i was create crud application using Mvc4(entityframework5)using database first approach its working fine,But i want to add the new column(field)in my db please helpme
Posted
Updated 25-Jan-14 2:09am
v2

1 solution

Just change your model with adding new column(field) in model class of your table and delete current database and run your application then it will create new database with new column added in database

But if you want to add column(field) without deleting existing database then you have to go through
'Code First Migration' (http://msdn.microsoft.com/en-us/data/jj554735.aspx[^]

hope this help.
 
Share this answer
 
v2
Comments
ilaya muthumanickam 25-Jan-14 7:23am    
I was trying code first also have the same problem we don't change the existing database.If suppose add the column it notify the error you have to delete the existing database....
SP HINGU 25-Jan-14 8:10am    
when you are using code first , you don't need to add column in database table. instead of add field in model class.
ilaya muthumanickam 25-Jan-14 7:29am    
please send any sample project regarding this particular issue..
SP HINGU 25-Jan-14 7:45am    
after adding new column(Field) in you model class
go Through these
In VS, go to Tools>Library package Manager > Package Manager Console
Type these command one by one which will automatically update your database.

Enable-Migrations –EnableAutomaticMigrations

Add-Migration anyname

Update-Database
ilaya muthumanickam 27-Jan-14 7:03am    
Thanks for ur kind reply i will try it now.............

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900