简体   繁体   English

如何指示实体框架基于当前数据库选择迁移?

[英]How do I instruct entity framework to choose migrations based on the current database?

So when a developer starts up our application locally, it will be against a blank, localhost database. 因此,当开发人员在本地启动我们的应用程序时,它将针对空白的localhost数据库。 But in production we will first need to migrate all of the old ASP.NET Membership Framework tables and data to the new ASP.NET Identity framework tables. 但是在生产中,我们首先需要将所有旧的ASP.NET Membership Framework表和数据迁移到新的ASP.NET Identity Framework表。

How can I write EF6 migrations to consider this? 如何编写EF6迁移来考虑这一点? Also, our existing production database has no __Migration table in it. 另外,我们现有的生产数据库中没有__Migration表。

When moving from Identity to Membership with data to be ported from old tables : You can create the tables that are according to Identity schema using SQL scripts. 从身份迁移到成员资格时,要从旧表移植数据 :您可以使用SQL脚本根据身份架构创建表。 Else if you change your app to use Identity, running and creating user a first time will create the tables for you via code first. 否则,如果您将应用程序更改为使用身份,第一次运行和创建用户将首先通过代码为您创建表。 You can then copy the data from the old tables through a console application or via SQL scripts. 然后,您可以通过控制台应用程序或SQL脚本从旧表中复制数据。

If you want to run migrations to create a new Identity tables before you run your application, you can do it by running the following steps - Enable-Migrations - Add-Migration - Update-Database 如果要在运行应用程序之前运行迁移以创建新的Identity表,则可以通过运行以下步骤来完成它-启用迁移-添加迁移-更新数据库

This will create the empty tables for your according to your DbContext. 这将根据您的DbContext创建空表。 If it extends from IdentityDbContext, it will create the tables according to Identity schema along with the _MigrationHistory table. 如果它是从IdentityDbContext扩展的,它将根据Identity架构和_MigrationHistory表一起创建表。 Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在实体框架中进行迁移? - How do I make migrations in Entity Framework? 实体框架6:如何使用代码优先迁移和FTP部署重置数据库 - Entity Framework 6: How do I reset a database using code first migrations and an FTP deploy 如何指示实体框架选择两个表之间具有多个外键的正确关系? - How do I instruct Entity Framework to select the correct relationship between two tables with multiple foreign keys between them? 实体框架迁移的数据库路径 - Database path for migrations of entity framework 实体框架中的跨数据库迁移 - Cross Database Migrations in Entity Framework Entity Framework 6 上的数据库迁移问题 - Issue with Database Migrations on Entity Framework 6 如何更新实体框架7迁移和数据库 - 代码优先 - How to update entity framework 7 migrations and database - Code first 如何从Visual Studio Team Services运行ASP.NET Core Entity Framework迁移 - How do I run ASP.NET Core Entity Framework migrations from Visual Studio Team Services 如何为IdentityServer4实体框架核心迁移指定架构? - How do I specify a schema for IdentityServer4 Entity Framework Core Migrations? 如何获得“实体框架代码优先”迁移来查看我的模型? - How do I get Entity Framework Code First Migrations to see my models?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM