2
Good afternoon, you guys.
I have an application that each client has their database and I am using the code first. To update I am always running in hand the command update-database -force
in the package console for each customer database. Does anyone know a way to automate this process? I did a search and found this link Entity-framework-code-first-Migration-to-Multiple-database, however error occurs while running update command.
I wish to have some script to update all databases automatically, ie a have a context that has more than one database on web.config
.
The error that occurred is as follows:
Automatic Migration was not Applied because it would result in data Oss. Set Automaticmigrationdatalossallowed to 'true' on your Dbmigrationsconfiguration to allow application of Automatic Migrations Even if they Might cause data Oss. Alternately, use Update-Database with the '-Force' option, or scaffold an Explicit Migration.
Which error occurred?
– Victor Stafusa
Follow the bug @Victorstafusa Automatic Migration was not Applied because it would result in data Loss. Set Automaticmigrationdatalossallowed to 'true' on your Dbmigrationsconfiguration to allow application of Automatic Migrations Even if they Might cause data Oss. Alternately, use Update-Database with the '-Force' option, or scaffold an Explicit Migration.]
– Zica
Automatic Migration was not Applied because it would result in data Oss. - Are you sure the size of the varchar fields is correct and there is no column or table missing?
– Victor Stafusa
update-database -force on console works, so that’s not the problem.
– Zica
And without the -force?
– Victor Stafusa
It also works.
– Zica
Well, the error message is saying there’s somewhere where it doesn’t work without the
-force
, And that’s why he doesn’t. And the reason he doesn’t is because some data would end up being lost somewhere. So I suggest you try to figure out which records and columns could cause some data loss in the migration and why. The-force
serves to it to go over all this and not to care if in fact some data loss will occur (which can be something dangerous).– Victor Stafusa
and how would I find that out? Do you have any idea? Using Automaticmigrationdatalossallowed = true works, plus I was worried about this data loss issue
– Zica
No, I don’t know. But with that, I think your question has been clarified. I’m going to vote to reopen.
– Victor Stafusa
@Victorstafusa I’d better ask a new question?
– Zica
No, don’t ask a new question. It would end up being closed as a duplicate of this. All you have to do is get four more people to reopen, which isn’t too hard, and I’m gonna help you with that.
– Victor Stafusa