i've created a project using this steps
Create Model; Create Controller from Model and scaffolding Views;
I've tried to access, and it works fine, but I've made some changes in Model rebuilt and tried to run one more time, and now i got this error:
{"The model backing the 'CodingContext' context has changed since the database was created. Consider using Code First Migrations to update the database ( http://go.microsoft.com/fwlink/?LinkId=238269 )."}
This error brings a null inner exception
and this is the stack:
at System.Data.Entity.CreateDatabaseIfNotExists
1.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass8.<PerformDatabaseInitialization>b__6() at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) at System.Data.Entity.Internal.RetryAction
1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1 action) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery
1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable
1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Coding.Controllers.CorController.Index() in c:\\Users\\Guilherme\\Documents\\Visual Studio 2012\\Projects\\Coding\\Coding\\Controllers\\CorController.cs:line 19 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2 parameters) at System.Web.Mvc.Async.As yncControllerActionInvoker.<>c_ DisplayClass42.b _41() at System.Web.Mvc.Async.AsyncResultWrapper.<>c_ DisplayClass81.<BeginSynchronous>b__7(IAsyncResult _) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult
1.End() at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c _DisplayClass37.<>c_ DisplayClass39.b _33() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c_ DisplayClass4f.b _49()
I think the problem is about refresing the database using this new Model, but i can't found any command that solve this problem.
Thanks in advance!
If Someone got the same problem, I got this answer with some friend help, you must to follow these steps to update your database:
Open The package manager console: Tools –> Library Package Manager –> Package Manager Console
Install Entity Framework: Install-Package EntityFramework
Run: Enable-Migrations
At this point I'd got problems, but the Visual Studio show me the answer, is just a problem of multiple Contexts
Run: Add-Migration
Then: Update-Database
And it's done, every change in you model, require to run these commands!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.