I have accidentally deleted data from __MigrationHistory table and I tried to make migration new tables and column changes to db. At this time EF6 show me an error
"There is already an object named 'xxxx' in the database.".
I tried the way by using this command and there is no effect on table column changes.
Add-Migration MyMigration1 -IgnoreChanges
Update-database -Force
There are many recommendation about this for recreating db or another else. But those ways might be effect data losing to my db which contains a huge size of tested data and I can't able to lost any data. How to solve this error by without losing any data. If anybody please...
Update
Finally I found the solution to solve my problem. I am not sure it's a prefer way to solve such kind of problems but it's worked for me.
I cleaned data from __MigrationHistory table,tried to migrate new db and I copied data from __MigrationHistory of new db to my old db, then I set AutomaticMigration true and run update-database command and the problem was solved.
I'm not sure if its good approach to fix that but it worked for me.
I just did insert into that table with proper version and names of the already applied migrations, I did it in EF Core and it works actually, but please wait for somebody to comfirm that what im writing about.
The problem I see there is that you need two more fields to be filled (in EF Core theres only two columns) but I think that you can receive them using for example SQL Profiler
Related
I am using visual studio with sql server, i am in a middle of a practice and faced a major issue.
The issue was in the first place, when i was creating a product table , by mistake i mistyped as a categoryId ctegoryId, and later i recorrected it by thinking its over.
And now I am almost done with the identity scaffolding when updating my database, I am facing such an error. and I've tried all ways to update it by myself but failed.
I need an expert guidance so I can continue my path till the end.
I do appreciate any solution from your side.
Thanks indeed [Migration error "Each Table must be unique"](https://i.stack.imgur.com/tB3iT.png)
Just to let you know, I have deleted my migration and reinstalled again without[NotMapped]in my product table"categoryID" and it worked back normally.
I am using EF6 with existing db and a separate new schema for my code first.
We were moving from staging to Production, and suddenly realized that all db's code first objects were gone, all beside the migration table.
Of course everybody blamed code first as the cause. Is it possible? or maybe someone deleted the objects manually by mistake?
In my Static Context constructor I used
Database.SetInitializer(new MigrateDatabaseToLatestVersion
I created the databases first, then used the wizards in Entity Framework 5 to create the models from the Database first. Over time, through development, I made changes to the models and let EF recreate them by deleting my database and then starting the project up and they magically appeared again with the changes I made to the columns . It worked great on SQL Express 2014. But Godaddy doesnt let EF do that, AND I have databases with names like "Hazards.Models.CompanyDataContext" that EF made and didnt ask me what I wanted to name them. How do I change the code so it will let me rename the database it uses, and if possible, incorporate it into the aspnetdb that mvc uses as an additional table (there already is simplemembership etc. in there.)?
Seeing as you used EF database first, rather than deleting your database and letting EF recreate it, have you thought about doing it the other way round?
You could use something like management studio express to rename your database tables/columns however you see fit. Then in Visual Studio, open your .edmx file, right-click the background and select 'update model from database'. This way you can add new tables to the model or update the models of existing tables from the database. Better still, you can take care of it all outside of godaddy.
Note: I found that when updating the EF model, just updating existing tables gives odd results sometimes. It's much more reliable when you delete tables from your .edmx first, then right-click and select 'update model from database', and add the tables back to your model.
I setuped CoreData using Magical Records with line
[MagicalRecord setupCoreDataStackWithStoreNamed:#"MyModel"];
Now in phase 2 of the app I'm doing
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:#"MyModel 2"];
but what happens is that the data gets cleared. Everything starts from scratch :( I'm in deep nuisance please help. Anybody?
When you make changes to an existing core data model you have to add a new version.
This doesn't mean that your data base name has changed, all thats happening is that you are telling Core Data that a new version has been added and thats where the auto migration magic can begin. Thats why you can open your .xcdatamodeld in finder, show package contents, and you will see your two versions.
So continue initialising Magical Record with the original model name: [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:#"MyModel"];
You should have a green tick next to MyModel.xcdatamodeld 2 in your file inspector:)
You also need to be aware that MagicalRecord will delete the model in Debug mode if it cannot perform migrations so please read the lightweight migration guide on how to setup valid model changes for lightweight migration
At the early stages of development, where data retention is no issue and experimental changes to the schema are expected to be numerous, is there a way to avoid migration? Namely, just to dump the database and start over each time.
Everything I try leads to the error: "The model used to open the store is incompatible with the one used to create the store".
Lightweight migration looks do-able, but I'll end up lots of unwanted versions and messy code. I'd also like to experiment with relationships (no wise cracks), but understand I'd need to commit to a heavyweight migration afterwards!
If the solution is to check for the existence of the original database using NSFileManager and delete/remove it if found, could someone please show the swift code with an example name of the original database, and how it can be effectively removed.
I've been trying several suggested solutions, such as dragging a copy of the .xcdatamodeld file onto the desktop, deleting the file in xcode and bringing it back in, but I keep getting the error that the model and store are not the same.
Answered in one line in first comment, but appreciated in reverse proportion.