0


You need to log in to create posts and topics.

Migration with existing Database

Dear Eben

i want migrataion and SeedAsync with existing database.

"ConnectionStrings": {
"DefaultConnection": "Server=Icom\\SQLEXPRESS;Database=icondb;Trusted_Connection=True;MultipleActiveResultSets=true"
},

 

Scloud.Std.Startup:Critical: Error whilst creating and seeding database

System.AggregateException: One or more errors occurred. (Database 'icondb' already exists. Choose a different database name.) ---> System.Data.SqlClient.SqlException: Database 'icondb' already exists. Choose a different database name.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---

 

Icondb had tables and sp.

we need to add quickapp tables and  default data into existing db

 

Thank you

vijay

 

 

Running migration into an existing database with tables is not supported out of the box in entityframework core.
You'll have to employ workarounds to achieve your goal.

This is a suggestion from an open issue in the entityframework github page on this matter
https://github.com/aspnet/EntityFrameworkCore/issues/2167

If you have an existing database and a model that maps to it, then scaffold an initial migration, but remove all the code in the Up and Down methods before applying it. This will get the model snapshot and history table in a state that is in-sync with the database. Now you can move forward with changing the model and applying migrations as normal.

Also there's a discussion on stackoverflow on this topic.
https://stackoverflow.com/questions/36741793/ef-7-migration-to-existing-database

Hope these put you on the right track.

Regards,
Eben Monney

Thank you