0

My start-up conditions:

  1. I have an application on .Net Core using EF Core (both 2.2);
  2. I have an existing database on local SQLServer;
  3. I use built-in DI to supply my DbContext: services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString));
  4. I use Fluent API to configure my context (empty method to start with) and DbContextOptions<MyDbContext> options constructor;
  5. I have several migrations from other projects existing in Database and no existing in my current project.

Using all of mentioned I perform (dotenet ef migrations add Initial --project ../MyDALProject) on an empty model to get an empty Initial Migration. That works fine. Then I run dotenet ef database update --project ../MyDALProject to apply this Empty Migration to the database. Nevertheless, I get "Database 'TargetDatabase' already exists. Choose a different database name".

BTW.: other projects work with the same Db just as fine.

What can be the problem? How to make it works?

P.S.: other projects' contextes, I have mentioned, are been scaffolded and mapped to some existing tables. After scaffold, migrations and updates work as expected. The problem relys only to this project, which will bring new tables to an existing db.

4

2 回答 2

1

After all, I decided to apply scripts to db manually and then found out, that db was inaccessible... Finally, I restored it and everything ran perfectly.

于 2018-12-12T02:27:50.767 回答
0

For me, I renamed the db dir which contains the mdf and logs dir. Had to give it back it's name to get the migration working.

Still inaccessibility issues.

于 2021-09-26T04:12:47.893 回答