I m new to MVC 4 ..I just make small application ..and two fields in class like Id,name now I need to add another field but its giving an error ..
The model backing the 'studentClass1DbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
The model backing
the 'studentClass1DbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
I am taking reference from the tutorial i found on net ..where it suggested to add field in MVC schema
-
1.
Have the Entity Framework automatically drop and re
-
create the dat
abase based on the new model class
schema. This approach is very convenient when doing active development on a test database; it allows
you to quickly evolve the model and database schema together. The downside, though, is that you lose
existing data in th
e database
—
so you
don't
want to use this approach on a production database!
2.
Explicitly modify the schema of the existing database so that it matches the model classes. The advantage
of this approach is that you keep your data. You can make this change e
ither manually or by creating a
database change script.
i need to go by using 2nd approcah ..as firts appraoch have some draw back and best suited for testing environmnet ..can any one recommend how to follow second appraoch to add field..apart from this it seems that first apprach is difficult
i need to go by using 2nd approcah ..as firts appraoch have some draw back and best suited for testing environmnet ..can any one recommend how to follow second appraoch to add field..apart from this it seems that first apprach is difficult
You can try Customize Profile to add new fields in the database table, please refer to the following link:
#Customize User's Profile in ASP.NET Identity System
Member
84 Points
1323 Posts
how to edit field in MVC framework
Oct 08, 2014 02:14 AM|erum|LINK
I m new to MVC 4 ..I just make small application ..and two fields in class like Id,name now I need to add another field but its giving an error ..
The model backing the 'studentClass1DbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
any help
All-Star
15186 Points
3888 Posts
Re: how to edit field in MVC framework
Oct 08, 2014 02:35 AM|raju dasa|LINK
Hi,
Since EF Code First has created Database, Adding a new field in db requires migrations cmd tool be used to update it, or
delete the db, from View->SolutionExplorer->serverName->urDBName
right click on DBName (its with different name in ur case) and select delete.
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 08, 2014 03:36 AM|erum|LINK
migrations cmd tool ??from where I can get ??
All-Star
15186 Points
3888 Posts
Re: how to edit field in MVC framework
Oct 08, 2014 04:40 AM|raju dasa|LINK
Hi,
Check this site:
http://msdn.microsoft.com/en-in/data/jj591621.aspx
rajudasa.blogspot.com || rajudasa-tech
All-Star
19919 Points
2016 Posts
Re: how to edit field in MVC framework
Oct 09, 2014 02:45 AM|Eileen ni - MSFT|LINK
Hi
Following this:
1. Open Package Manager Console from Tools -> Libraray Package Manager -> Package Manager Console
2. PM> Enable-Migrations -ContextTypeName <TheDatabaseName>
3. Set AutomaticMigrationsEnabled=true, from Migrations folder of Configuration file
4. PM> Add-Migration InitialCreate
5. PM> Update-Database
You can refer to the following tutorial:
#Adding a New Field
http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-a-new-field
Hope this can be helpful.
Best Regards,
Eileen
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 10, 2014 10:26 PM|erum|LINK
i write like this way on
PM > Enable-Migrations -ContextTypeName <studentClass1DbContext>
it gives follwoing error any help
The '<' operator is reserved for future use.
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 12, 2014 07:42 AM|erum|LINK
I m getting following message
Migrations have already been enabled in project 'Student'. To overwrite the existing migrations configuration, use the -Force parameter.
when type this line
but unable to find Set AutomaticMigrationsEnabled=true, from Migrations folder of Configuration file ..
here is configuration.cs
namespace
Student.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
internal sealed class Configuration : DbMigrationsConfiguration<Student.Models.studentClass1DbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled =
false;
}
protected override void Seed(Student.Models.studentClass1DbContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
}
}
}
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 12, 2014 07:45 AM|erum|LINK
oh I find AutomaticMigrationsEnabled = false;
I make it true but same error
The model backing the 'studentClass1DbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 12, 2014 08:00 AM|erum|LINK
ok so far so good
when I added dob in field in database just one time ..but it gives error
Column names in each table must be unique. Column name 'dob' in table 'dbo.studentClass1' is specified more than once.
though dbo.studentclass1.contain only 1 in design time
any help
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 14, 2014 12:52 AM|erum|LINK
is there any other alternative to do this (check following link)
http://msdn.microsoft.com/en-us/data/jj591621
All-Star
19919 Points
2016 Posts
Re: how to edit field in MVC framework
Oct 15, 2014 05:14 AM|Eileen ni - MSFT|LINK
Hi erum,
Thanks for your post.
I set a Angle brackets, it means it is mark.you don't add Angle brackets(<xxx>) mark
You can follow this:
Like this:
I recommend that you can read the above link carefully that my previous reply.
Hope this can be helpful.
Best Regards,
Eileen
Member
84 Points
1323 Posts
Re: how to edit field in MVC framework
Oct 16, 2014 05:51 AM|erum|LINK
I am taking reference from the tutorial i found on net ..where it suggested to add field in MVC schema
i need to go by using 2nd approcah ..as firts appraoch have some draw back and best suited for testing environmnet ..can any one recommend how to follow second appraoch to add field..apart from this it seems that first apprach is difficult
All-Star
19919 Points
2016 Posts
Re: how to edit field in MVC framework
Oct 22, 2014 02:17 AM|Eileen ni - MSFT|LINK
Hi erum,
Thanks for your reply.
According to your description,
You can try Customize Profile to add new fields in the database table, please refer to the following link:
#Customize User's Profile in ASP.NET Identity System
http://www.itorian.com/2013/11/customize-users-profile-in-aspnet.html
I have tested it,it worked.
Hope this can be helpful.
Best Regards,
Eileen