代码首次迁移更新localDB上的错误DB
-
21-12-2019 - |
题
我正在使用代码首次迁移来为我的ASP MVC站点创建和更新数据库。
我有一个dbcontext,它在解决方案中的另一个项目中。
public class EFDbContext : DbContext
{
public DbSet<Book> Books { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Publisher> Publishers { get; set; }
}
.
当我启用迁移和add-migration [name] 时。它似乎创建了自己的数据库,称为
[foo-projectname].Domain.Concrete.EFDbContext
.
而不是附加到我创建的数据库,称为 [foo-projectname] 。 在网站的WebConfig中,连接字符串由目录“ [foo-projectname] ”引用。
如果我将webconfig更改为另一个数据库,那么我从我添加到该数据库中的项目获取结果。但是我想使用我创建的数据库。
我不想坚持使用此自动创建的原因是因为我不确定迁移到SQLServer,不希望在线进一步陷入困境。我也得到了错误
模型备份“efdbcontext”上下文已更改以来...
即使我没有改变任何东西。
解决方案
x是包含派生属世纪icetagcode类的项目名称。
- 确保
DbContext
上的Default project
是x - 确保解决方案上的活动启动项目是x
另一个解决方法,在运行迁移语法时提供以下参数。
-ProjectName X -StartUpProjectName X
.
一些参数描述:
-ProjectName <String>
Specifies the project that contains the migration configuration type to be
used. If omitted, the default project selected in package manager console
is used.
-StartUpProjectName <String>
Specifies the configuration file to use for named connection strings. If
omitted, the specified project's configuration file is used.
-ConfigurationTypeName <String>
Specifies the migrations configuration to use. If omitted, migrations will
attempt to locate a single migrations configuration type in the target
project.
-ConnectionStringName <String>
Specifies the name of a connection string to use from the application's
configuration file.
-ConnectionString <String>
Specifies the the connection string to use. If omitted, the context's
default connection will be used.
. 不隶属于 StackOverflow