阻止EF尝试创建初始数据库

Cli*_*ark 8 c# asp.net entity-framework asp.net-identity

所以我成功地获得了创建和初始化Identity数据库的解决方案.现在的问题是,当我正在努力时,我不断收到此错误

Cannot create file 'C:\Webs\SomeScheduler\SomeScheduler\App_Data\SomeSchedulerUsers.mdf' 
because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in 
the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot create file 
'C:\Webs\SomeScheduler\SomeScheduler\App_Data\SomeSchedulerUsers.mdf' 
because it already exists. Change the file path or the file name, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Run Code Online (Sandbox Code Playgroud)

我知道它已经存在,这就是我想要的.每当我在开发此站点时尝试运行代码时,如何阻止它重新创建它?

一如既往,非常感谢任何和所有的帮助.

bat*_*che 7

将以下行添加到上下文构造函数中

Database.SetInitializer<YourContextClass>(null);
Run Code Online (Sandbox Code Playgroud)

这应该足够了.

但是,如果您只想在数据库不存在且正确配置迁移时创建数据库,请查看此问题如何避免使用自动代码优先迁移重新创建现有数据库