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
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.
migrations cmd tool ??from where I can get ??
Hi,
erum
migrations cmd tool ??from where I can get ??
Check this site:
Hi
erum
migrations cmd tool ??from where I can get ??
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
i write like this way on
PM > Enable-Migrations -ContextTypeName <studentClass1DbContext>
it gives follwoing error any help
The ‘<’ operator is reserved for future use.
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" }
//
);
//
}
}
}
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).
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
is there any other alternative to do this (check following link)
Hi erum,
Thanks for your post.
erum
PM > Enable-Migrations -ContextTypeName <studentClass1DbContext>
it gives follwoing error any help
The ‘<’ operator is reserved for future use.
I set a Angle brackets, it means it is mark.you don’t add Angle brackets(<xxx>) mark
You can follow this:
PM > Enable-Migrations -ContextTypeName YournameSpace.studentClass1DbContext
Like this:
Enable-Migrations -ContextTypeName MvcMovie.Models.MovieDBContext
I recommend that you can read the above link carefully that my previous reply.
Hope this can be helpful.
Best Regards,
Eileen
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
Hi erum,
Thanks for your reply.
According to your description,
erum
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
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