简体   繁体   English

实体框架6:如何使用代码优先迁移和FTP部署重置数据库

[英]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.

相关问题 如何使用Visual Studio实体框架代码优先迁移将发布部署到mysql数据库 - How to deploy publish to mysql database using visual studio entity framework code first migrations 使用Entity Framework代码优先迁移来更改数据库表名称 - Change a database table name using Entity Framework code first migrations 如何更新实体框架7迁移和数据库 - 代码优先 - How to update entity framework 7 migrations and database - Code first 如何首先使用EF代码重置数据库迁移? - How to reset database migrations using EF code first? 如何获得“实体框架代码优先”迁移来查看我的模型? - How do I get Entity Framework Code First Migrations to see my models? 如何使用C#-WPF-Entity-Framework Code First应用程序创建数据库备份? - How do I create database backups using C#-WPF-Entity-Framework Code First application? 如何在 MVC3 和实体框架上使用 Code First 将另一个表添加到我的数据库中? - How do I add another table to my database using Code First on MVC3 and Entity Framework? 数据库实体框架代码中的额外表格首先使用数据库迁移 - Extra table in database Entity Framework Code First With Database Migrations 实体框架代码第一次迁移 - Entity Framework Code First Migrations 如何使用代码迁移配置禁用延迟加载,实体框架4.1 - How Do I Disable Lazy Loading, Entity Framework 4.1 using Code Migrations Configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM