gpt4 book ai didi

sql-server - 是否可以在 ASP.NET Core 中使用多个数据库的数据库迁移?

转载 作者:行者123 更新时间:2023-12-03 03:48:50 25 4
gpt4 key购买 nike

在我的 ASP.NET Core 应用程序中,我有两种应用程序设置,一种用于生产,一种用于开发。我还使用数据库迁移来管理我的数据库,也就是说,由于它们是两个连接字符串,我只能从 Visual Studio 更新开发数据库。我的问题是,是否可以针对两个连接字符串运行数据库迁移?即我存储在 appsettings.Production.jsonappsettings.Development.json 中的连接字符串?

appsettings.Development.json

{     
"ConnectionStrings": {
"DevConnection": "Server=tcp:devdatabase.database.windows.net,1433;Initial Catalog=MyDevelopment;Persist Security Info=False;User ID=whatever;Password=whatever;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
},
"AllowedHosts": "*"
}

appsettings.Production.json

{     
"ConnectionStrings": {
"ProdConnection": "Server=tcp:proddatabase.database.windows.net,1433;Initial Catalog=MyProduction;Persist Security Info=False;User ID=whatever;Password=whatever;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
},
"AllowedHosts": "*"
}

我的两个数据库都存储在 Azure 中,通常如果我想要进行更改,我会通过以下方式创建迁移:

Add-Migration AddedBoolColumns

随后

Update-Database

迁移采用开发连接字符串并更新开发数据库,​​但生产保持不变,有时我希望这些更改也能传递到该数据库。有办法做到这一点吗?

最佳答案

如果您想从本地计算机运行迁移,您可以将连接字符串作为参数添加到 Update-Database 中。下面的例子。

Update-Database -Connection your_connection_string

话虽如此,您可以将迁移运行到任意数量的数据库 ^^

关于sql-server - 是否可以在 ASP.NET Core 中使用多个数据库的数据库迁移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67818569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com