Migrations on Entity Framework Multiple Developers Issue - entity-framework

We are working with Code First Migrations EF 5.0.0.rc and we are having problems when two people on the team create migrations at the same time and then commit their changes.
This looks because the Update-Database compares again the latest migration model hash or something that does not have my changes because it was commited by someone else. So is based in the database state of the latest migration, and then ignoring the changes I already applied previously.
This is a very ugly behaviour when working with local databases to simplify development and remote work. I guess this should work different, always using the current model for comparison and not the latest one declared in the Migration file model hash.
Or we are doing something wrong? Anybody with this issue?
The migration tool is really awesome, but it's very difficult to work on diverse environments, remote without this feature working fine and we are struggling our head because this looks very basic feature.
Thanks,
Leonardo

Related

Entity Framework MIgrations working in a project with many developers

I have a project using EF migrations, I just need to confirm if we need to adjust anything or maybe a parameter in case more than one person is doing changes on the DB project. For example, yesterday a coworker was adding a column in a table and pushed the changes on the git project. I did get latest and today I need to do another db change in another table and when I create a new migration, the script is pushing the change my coworker did. Is there any wrong in the configuration?

How can I control database version without losing data, more like of github

I am using postgres for my database and because our product is in development mode, sometimes we need to change our database scheme. If we find some problem in that we need to revert our changes, We have to do this manually. Although we have a option to make database backup before making any change. But I was looking for some solution more kind of git. So, that we don't have to do this manually.
I would suggest you script the creation of your database. Save this SQL script in a SqlScripts directory at the base of your project and check this into source control with the rest of your project. Then if you need to alter your database schema, you alter or add to you SQL script or scripts. In that way the structure of your database is versioned but the data is not in source control, which you would not typically want to do.
One short-coming here is you may have to manually run this script when reverting commits, but this isn't a situation that should happen too often.

How to check if database changes exist - Entity Framework Core

Let's say I have been coding for a couple days and can't remember if I made any changes to the database. What I currently do is go to the package manager console and "add-migration" and see if any changes exist. If none, then I delete my migration. If I do have changes then I still delete my migration and re-add the migration with a better migration name that reflects the actual change.
Is there anything with Entity Framework Core that will inform me that changes exist or something that will tell me the changes that exist without actually creating a migration file and updating the snapshotContext?
I know I could look through the change logs of my db entities but it becomes a hassle when I have several commits.

Why does Entity Framework Database First overrides on delete no action

I have an Entity Framework Project for a WinForms application and the approach that I'm using is Database First.
And here is my setup (I keep it as simple as possible):
Sql Database Model
Entity Framework Model
The problem is when I try to delete a department using the command:
context.Departamento.Remove(departamento)
It deletes every record on DepartamentoComputadora table instead of throwing an exception for the "On Delete No Action" constraint in the database.
The weird thing is that if I try to delete that department on my database it actually does not let me delete it because of the constraint.
Is any configuration that I am missing on EF to enforce the on delete no action?
It is weirder that the actual configuration of EF shows the behavior that I expect to have on the table.
Thank you in advance!
Actually, it was my fault with some issues with Git on Visual Studio. My model got broken when I committed staged changes and then even I was deleting, uninstalling EF, installing it again and recreating the model from scratch, some files were not deleted from my project folder and that was causing the problem.
The solution was pretty simple:
Creating a branch for the fix.
Deleting the Entity Data Model.
Uninstall EF and removed all left lines on app.config file referencing EF.
Installing EF again.
Creating the model again and committing changes.
Done.
Thank you very much!

How to customise Migrations History table after first migration was applied

I am trying to relate Migrations History entries to version of software by which migration was performed. So far best place for that seems additional column in Migrations History table which can be filled with software version against each migration.
This article nicely describes how to make it, however it states:
Before you start you need to know that you can customize the
migrations history table only before you apply the first migration.
I don't believe this. Is there any way of achieving this? Maybe it is possible to change this table within another migration, however I am not sure about consequences, can anyone please advice on this matter?