I have an existing database in production which have not previously been involved with EF Migrations. As such, it is missing the __EFMigrationsHistory table.
I'm doing the following:
- Invoking
Add-Migration InitialCreate
- Running the application
- Stopping the application
- Adding my modifications to the model
- Invoking
Update-Database
- Getting the error Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'sometablename' in the database.
I'm assuming this occurs because there is no migration history, and it tries to create everything from scratch.
How can I add migrations to a database which have not previously used it?
CodePudding user response:
- If you are sure that your EF model matches the existing database's model then you can create the Migration History table manually and add row entries for the migrations which match the existing database models.
- If you have a large database it will be hard for you to confirm that the database model matches your new EF model. You will have to create a new database, run your migration on the new database and export data table by table from old to new.