[英]Entity Framework 6: How do I reset a database using code first migrations and an FTP deploy
I deploy to a staging server that I don't have control over and have only been given FTP access. 我部署到我无法控制的登台服务器,仅获得了FTP访问权限。 I've successfully used EF6 Code Migrations to create and seed the database on the staging server using the method described here . 我已经成功地使用EF6代码迁移,使用此处描述的方法在登台服务器上创建数据库并将其播种。
I would like to basically do the equivalent of the following, but in code, when I deploy via FTP: 当我通过FTP进行部署时,我想基本上执行以下等效操作,但在代码中:
Update-database -TargetMigration:0
Update-database
My goal: I have new seed data to replace the existing data. 我的目标:我有新的种子数据来替换现有数据。
Any help is appreciated! 任何帮助表示赞赏!
As usual I always figure it out moments after posting a question. 像往常一样,我总是会在发布问题后立即找出答案。 (I promise I was looking for a long time before finally posting) (我保证在发布之前,我已经找了很长时间)
I did not realize you could pass a ConnectionString argument to Update-Database. 我没有意识到您可以将ConnectionString参数传递给Update-Database。 So basically this was all I needed in the end: 所以基本上这就是我最终需要的:
Update-database -TargetMigration:0 -ConnectionString "MY_STAGING_CONNECTION_STRING" -ConnectionProviderName "System.Data.SqlClient"
And then on my next deploy it automatically migrated back to the latest version. 然后在我的下一次部署中,它会自动迁移回最新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.