?
Solved

update an sql server database using  entity framework code first migration

Posted on 2015-01-23
5
Medium Priority
?
210 Views
Last Modified: 2015-01-29
Hi.
I have an application that uses a local database. And I have something like 300 databases to update. All of them in remote places.
I then created an application that has two projects. a model with the database tables and another to the context ..
then follow the sequence:
1. the development machine ran the application. that's perfect. created the database.
2. altered a model class.
3. ran the "enable-migrations"
3. ran the "add-migration class1"
4. I ran the "update-database"

worked perfectly.

copied the compiled application and took her to a remote machine. I ran the application and it worked perfectly.

I returned the development machine and changed a new class. performed the following:
1. "add-migration class2"
2. "update-database"

worked perfectly.

I copied the compiled application and took to the remote machine (the same) and ran the program and get an exception saying that the context has changed since the database was created and that I must consider the code first migration.

I will use the program exactly not to need the presence on site.

Where am I going wrong?
0
Comment
Question by:Deraldo Silva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 40566198
Could you please put exact exception you got?
0
 

Author Comment

by:Deraldo Silva
ID: 40566693
Sure.

Unhandled Exception: System.InvalidOperationException: The model backing the 'Db
BancoContexto' context has changed since the database was created. Consider usi
ng Code First Migrations to update the database (http://go.microsoft.com/fwlink/
?LinkId=238269).
   at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext
 context)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateIn
itializationAction>b__e()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Ac
tion action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization(
)
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(I
nternalContext c)
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(A
ction`1 action)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType
(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, Ent
ityState newState, Object entity, String methodName)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
   at System.Data.Entity.DbSet`1.Add(TEntity entity)
   at GenerateDatabase.Program.Main(String[] args) in c:\Projects\GenerateDataba
se\GenerateDatabase\Program.cs:line 19
0
 

Author Comment

by:Deraldo Silva
ID: 40568020
Hi.

If I use this Database.SetInitializer<DbBancoContexto>(null); the application runs but the migration is not applied. If I take it off, I got the error above.
0
 

Accepted Solution

by:
Deraldo Silva earned 0 total points
ID: 40568024
This works.

very nice. thx to "tilde" @internet.

Database.SetInitializer<DbBancoContexto>(new MigrateDatabaseToLatestVersion<DbBancoContexto, GenerateDatabase.Migrations.Configuration>());

Open in new window

0
 

Author Closing Comment

by:Deraldo Silva
ID: 40577049
I do not want the credit for the solution. I am just setting as solution for someone use.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question