我在Blazor Wasm,AppSettings.json文件中有一个项目,我有两个连接字符串,一个与开发数据库的点,另一个是生产数据库,生产数据库是开发数据数据库的副本。
AppSettings。 JSON文件:
"AllowedHosts": "*",
"ConnectionStrings": {
"SqlConnectionDesarrollo": "Data Source=10.0.0.41;Initial Catalog=QaInventarios;User ID=Innovacion;Password=***;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
"SqlConnectionProduccion": "Data Source=10.0.0.41;Initial Catalog=Inventarios;User ID=Innovacion;Password=***;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
},
启动文件:
services.AddDbContext<ApplicationDbContext>
(options => options.UseSqlServer(Configuration.GetConnectionString("SqlConnectionDesarrollo")));
问题是要执行迁移,我要做的是评论连接字符串,具体取决于我要使用的数据库并更改启动中的名称,我知道这是一个不好的练习,但我不知道如何优化这一点,然后执行:
Add-Migration NameMigration
Update-Database
要执行迁移,在开发数据库中它运行良好,创建了新的迁移并进行了更改,然后我运行 update-date-database
命令再次更新生产数据库和更改未进行,也没有添加新的迁移,并且没有进行更改,如果我删除任何使用 remove overmigration -force
然后更新的迁移,也会发生同样的事情。 -database
我的数据库中存在不一致之处,我该如何执行
迁移,两者的变化,并且它们保持完全相同?
I have a project in blazor wasm, in the appsettings.json file I have two connection strings, one points to the development database and the other to the production database, the production database is a copy of the database of development data.
appsettings. json file:
"AllowedHosts": "*",
"ConnectionStrings": {
"SqlConnectionDesarrollo": "Data Source=10.0.0.41;Initial Catalog=QaInventarios;User ID=Innovacion;Password=***;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
"SqlConnectionProduccion": "Data Source=10.0.0.41;Initial Catalog=Inventarios;User ID=Innovacion;Password=***;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
},
startup file:
services.AddDbContext<ApplicationDbContext>
(options => options.UseSqlServer(Configuration.GetConnectionString("SqlConnectionDesarrollo")));
the problem is that to perform a migration what I do is comment a connection string depending on the database I want to use and changing the name in the startup, I know it's a bad practice but I don't know how to optimize this, then I execute:
Add-Migration NameMigration
Update-Database
to perform a migration, in the development database it works fine, a new migration is created and the changes are made, then I run the Update-Database
command again to update the production database and the changes are not made and are not added the new migration and the changes are not made, the same thing happens if I delete any migration with Remove-Migration -Force
and then an Update-Database
there are inconsistencies in my database, how can I perform
migrations, changes in both and that they remain exactly the same ??
发布评论
评论(1)
在EF Core 5.0中,在EF Core CLI工具中引入了连接字符串选项。
示例
开发的
dotnet ef数据库更新 - 连接&lt;开发连接字符串&gt;
和生产。
dotnet ef数据库更新 - connection&lt;生产连接字符串&gt;
关于 dotnet ef Update
In EF Core 5.0, a connection string option is introduced in the EF Core CLI tool.
Example
For Development
dotnet ef database update --connection <Development Connection string>
And for Production.
dotnet ef database update --connection <Production Connection string>
Documentation about dotnet ef update