[英]Why does EF Core throws "Database already exists"?
My start-up conditions:我的启动条件:
services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString))
;services.AddDbContext<MyDbContext>(options => options.UseSqlServer(connectionString))
;DbContextOptions<MyDbContext> options
constructor;DbContextOptions<MyDbContext> options
构造函数; Using all of mentioned I perform ( dotenet ef migrations add Initial --project ../MyDALProject
) on an empty model to get an empty Initial Migration.使用所有提到的我在一个空模型上执行(
dotenet ef migrations add Initial --project ../MyDALProject
)以获得一个空的初始迁移。 That works fine.这很好用。 Then I run
dotenet ef database update --project ../MyDALProject
to apply this Empty Migration to the database.然后我运行
dotenet ef database update --project ../MyDALProject
将此空迁移应用到数据库。 Nevertheless, I get "Database 'TargetDatabase' already exists. Choose a different database name" .不过,我得到"Database 'TargetDatabase' already exists. Choose a different database name" 。
BTW.: other projects work with the same Db just as fine.顺便说一句。:其他项目也可以使用相同的 Db。
What can be the problem?可能是什么问题? How to make it works?
如何使它起作用?
PS: other projects' contextes, I have mentioned, are been scaffolded and mapped to some existing tables. PS:其他项目的上下文,我已经提到,被脚手架并映射到一些现有的表。 After scaffold, migrations and updates work as expected.
在脚手架之后,迁移和更新按预期工作。 The problem relys only to this project, which will bring new tables to an existing db.
问题仅取决于这个项目,它将把新表带到现有的数据库中。
毕竟,我决定手动将脚本应用到 db,然后发现,db 无法访问……最后,我恢复了它,一切运行良好。
For me, I renamed the database directory which contains the mdf and logs directory.对我来说,我重命名了包含 mdf 和日志目录的数据库目录。 Had to give it back its name to get the migration working.
必须将其名称归还才能使迁移正常工作。
Still inaccessibility issues.仍然无法访问的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.