ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程-阿里云开发者社区

开发者社区> 杰克.陈> 正文

ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程

简介: 原文:ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core Identity 迁移数据 上一章节中我们配置了 Identity ,也让我们的应用程序正常运行起来了,在访问未授权页面的时候会跳转到 /Accout/Login 页面。
+关注继续查看

原文:ASP.NET Core Identity 迁移数据 - ASP.NET Core 基础教程 - 简单教程,简单编程

ASP.NET Core Identity 迁移数据

上一章节中我们配置了 Identity ,也让我们的应用程序正常运行起来了,在访问未授权页面的时候会跳转到 /Accout/Login 页面。接下来我们就要实现登录的功能

但是,咦,好像还没创建用户表呢..哎呀,不是没创建用户表,而是没做 Identity 的数据迁移

那么,本章节接下来的内容,就开始迁移 Identity 数据呗

数据库连接配置

对了,我在看官方文档的过程中,发现了两种配置数据库连接的方法

一、第一种是在 Startup 类中的 ConfigureServices 方法中配置

services.AddEntityFrameworkSqlite().AddDbContext<HelloWorldDBContext>(options => options.UseSqlite(Configuration["database:connection"]));

这种方法需要我们的 HelloWorldDBContext 有一个可以接受 DbContextOptions<HelloWorldDBContext> 类型参数的构造函数

public HelloWorldDBContext(DbContextOptions<HelloWorldDBContext> options)
    : base(options)
{ 
}

二、第二种方法只需要在 HelloWorldDBContext 类中重写方法 OnConfiguring

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { 
    optionsBuilder.UseSqlite("Data Source=blogging.db"); 
}

然后在 Startup 类中的 ConfigureServices 方法种就可以这么写了

services.AddEntityFrameworkSqlite().AddDbContext<HelloWorldDBContext>();

看起来是不是第二种更简单更方便更简洁

后知后觉,醉了,这次,我们就使用这种方法吧,然后将其它相关的都统统删掉

  1. 首先删除 Startup 类中的 ConfigureServices 方法中的相关配置

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    
        services.AddEntityFrameworkSqlite().AddDbContext<HelloWorldDBContext>();
    
        services.AddIdentity<User, IdentityRole>().AddEntityFrameworkStores<HelloWorldDBContext>();
    
    }
    
  2. 其次在 HelloWorldDBContext 类中重写方法 OnConfiguring,且删除带参数的构造函数

    其实删除了带参数的构造函数,那么不带参数的构造函数也可以删除了,于是就变成了

    using System;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    
    namespace HelloWorld.Models
    {
        public class HelloWorldDBContext:IdentityDbContext<User>
        {
    
            public DbSet<Employee> Employees { get; set; }
    
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                optionsBuilder.UseSqlite("Data Source=blogging.db");
            }
        }
    }
    

    这种方法我还没找到如何引用 Configuration 属性的方式,如果你知道,请麻烦告诉我下

重启下我们的应用程序,刷新下首页,看看是否正常输出

最佳实战

实际应用中,你千万不要像我这么激进,因为这两种方式是互补的关系,也就是说 OnConfiguring() 方法可以覆写传递给 HelloWorldDBContext(DbContextOptions<HelloWorldDBContext> options) 的连接

当一个应用需要连接多个数据库的时候,结合这两种方式非常有用,第一种方式用于默认的数据库,第二种方式用于特定的数据库

迁移 Identity 数据

好了,让我门言归正传吧,开始迁移 Identity 数据。其实前面的 EF 框架中我们已经迁移过一次了,不知道大家是否还记得如何迁移呢

  1. 首先停止我们的应用程序,不然会报错,因为我们使用的是文件系统数据库

  2. 其次打开 控制台窗口 ( 终端或 Power Shell 或 命令提示符 ),定位到我们的 HelloWorld 项目下

    $ cd ~/Developer/aspnetcore/HelloWorld/HelloWorld
    

    我用的是 macOS,且我的 HelloWorld 保存在 ~/Developer/aspnetcore/HelloWorld/HelloWorld

    然后使用 ls 命名就可以列出当前目录下的所有文件和子目录

    $ ls
    AppSettings.json  Controllers  HelloWorld.csproj  Models  Program.cs  Properties  Startup.cs  Views  bin  obj  wwwroot
    

    如果你使用的是 Windows,且使用的不是 Power Shell,那么你应该使用 dir 命令而不是 ls 命令

    如果能看到 HelloWorld.csproj 则说明处于正确的目录,否则你应该继续 cd 到该目录下

  3. 然后可以运行下列命令创建迁移代码

    dotnet ef migrations add InitialIdentity -v
    
    参数 说明
    dotnet 是 .NET 框架所有命令的开始标识
    ef 是指使用 Entity Framework 提供的命令
    migrations 是指使用迁移命令
    add 是指添加迁移
    InitialCreate 是本次迁移的说明,你可以改成任意文本,但我们推荐最好是能清楚的描述本次迁移的意图
    -v 参数用于输出创建迁移代码时的运行日志,方便出错时我们可以查看错在哪里

    运行结果如下

    $ dotnet ef migrations add InitialIdentity -v
    Using project '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj'.
    Using startup project '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj'.
    Writing '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/obj/HelloWorld.csproj.EntityFrameworkCore.targets'...
    dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/yk/2446sljj6hn82nvzkdgxltmw0000gn/T/tmpbjHVNk.tmp /verbosity:quiet /nologo /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj
    Writing '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/obj/HelloWorld.csproj.EntityFrameworkCore.targets'...
    dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/yk/2446sljj6hn82nvzkdgxltmw0000gn/T/tmpDgtTNf.tmp /verbosity:quiet /nologo /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj
    dotnet build /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj /verbosity:quiet /nologo
    
    Build succeeded.
        0 Warning(s)
        0 Error(s)
    
    Time Elapsed 00:00:03.64
    dotnet exec --depsfile /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.deps.json --additionalprobingpath /Users/yufei/.nuget/packages --additionalprobingpath /usr/local/share/dotnet/sdk/NuGetFallbackFolder --runtimeconfig /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.runtimeconfig.json /usr/local/share/dotnet/sdk/2.1.301/DotnetTools/dotnet-ef/2.1.1/tools/netcoreapp2.1/any/tools/netcoreapp2.0/any/ef.dll migrations add InitialIdentity --assembly /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.dll --startup-assembly /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.dll --project-dir /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/ --language C# --working-dir /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld --verbose --root-namespace HelloWorld
    Using assembly 'HelloWorld'.
    Using startup assembly 'HelloWorld'.
    Using application base '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1'.
    Using working directory '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld'.
    Using root namespace 'HelloWorld'.
    Using project directory '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/'.
    Finding DbContext classes...
    Finding IDesignTimeDbContextFactory implementations...
    Finding application service provider...
    Finding IWebHost accessor...
    Using environment 'Development'.
    Using application service provider from IWebHost accessor on 'Program'.
    Found DbContext 'HelloWorldDBContext'.
    Finding DbContext classes in the project...
    Using context 'HelloWorldDBContext'.
    Finding design-time services for provider 'Microsoft.EntityFrameworkCore.Sqlite'...
    Using design-time services from provider 'Microsoft.EntityFrameworkCore.Sqlite'.
    Finding design-time services referenced by assembly 'HelloWorld'.
    No referenced design-time services were found.
    Finding IDesignTimeServices implementations in assembly 'HelloWorld'...
    No design-time services were found.
    DetectChanges starting for 'HelloWorldDBContext'.
    DetectChanges completed for 'HelloWorldDBContext'.
    DetectChanges starting for 'HelloWorldDBContext'.
    DetectChanges completed for 'HelloWorldDBContext'.
    DetectChanges starting for 'HelloWorldDBContext'.
    DetectChanges completed for 'HelloWorldDBContext'.
    DetectChanges starting for 'HelloWorldDBContext'.
    DetectChanges completed for 'HelloWorldDBContext'.
    Writing migration to '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/Migrations/20180624040354_InitialIdentity.cs'.
    Writing model snapshot to '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/Migrations/HelloWorldDBContextModelSnapshot.cs'.
    'HelloWorldDBContext' disposed.
    Done. To undo this action, use 'ef migrations remove'
    

    大概意思就是经过漫长的岁月,成功创建了迁移代码

    这一步非常容易出错,如果你有任何错误,欢迎你在讨论区留下你包括的意见

    ASP.NET Core 讨论区

  4. 创建迁移成功后,我们就可以使用下面的命令查看当前有多少迁移代码和它们的状态

    $ dotnet ef migrations list
    

    运行结果如下

    $ dotnet ef migrations list
    20180623011249_InitialCreate
    20180624040354_InitialIdentity
    

    可以看到总共有两个迁移代码,下面那个 20180624040354_InitialIdentity 就是我们刚刚创建

    在解决方案管理器中我们还可以看到 Migrations 又多了很多文件

  5. 接下来我们就要开始应用这些迁移来更新数据库,执行下面的命令来应用迁移代码

    $ dotnet ef database update -v
    
    参数 说明
    dotnet 是 .NET 框架所有命令的开始标识
    ef 是指使用 Entity Framework 提供的命令
    database 是指使用数据库相关命令
    update 是指更新数据库
    -v 参数用于输出创建迁移代码时的运行日志,方便出错时我们可以查看错在哪里

    执行以上命令,输出结果如下

    $ dotnet ef database update -v
    Using project '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj'.
    Using startup project '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj'.
    Writing '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/obj/HelloWorld.csproj.EntityFrameworkCore.targets'...
    dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/yk/2446sljj6hn82nvzkdgxltmw0000gn/T/tmp6jVQsB.tmp /verbosity:quiet /nologo /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj
    Writing '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/obj/HelloWorld.csproj.EntityFrameworkCore.targets'...
    dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/yk/2446sljj6hn82nvzkdgxltmw0000gn/T/tmpXNRfCA.tmp /verbosity:quiet /nologo /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj
    dotnet build /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/HelloWorld.csproj /verbosity:quiet /nologo
    
    Build succeeded.
        0 Warning(s)
        0 Error(s)
    
    Time Elapsed 00:00:04.59
    dotnet exec --depsfile /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.deps.json --additionalprobingpath /Users/yufei/.nuget/packages --additionalprobingpath /usr/local/share/dotnet/sdk/NuGetFallbackFolder --runtimeconfig /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.runtimeconfig.json /usr/local/share/dotnet/sdk/2.1.301/DotnetTools/dotnet-ef/2.1.1/tools/netcoreapp2.1/any/tools/netcoreapp2.0/any/ef.dll database update --assembly /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.dll --startup-assembly /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1/HelloWorld.dll --project-dir /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/ --language C# --working-dir /Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld --verbose --root-namespace HelloWorld
    Using assembly 'HelloWorld'.
    Using startup assembly 'HelloWorld'.
    Using application base '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/bin/Debug/netcoreapp2.1'.
    Using working directory '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld'.
    Using root namespace 'HelloWorld'.
    Using project directory '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/'.
    Finding DbContext classes...
    Finding IDesignTimeDbContextFactory implementations...
    Finding application service provider...
    Finding IWebHost accessor...
    Using environment 'Development'.
    Using application service provider from IWebHost accessor on 'Program'.
    Found DbContext 'HelloWorldDBContext'.
    Finding DbContext classes in the project...
    Using context 'HelloWorldDBContext'.
    Finding design-time services for provider 'Microsoft.EntityFrameworkCore.Sqlite'...
    Using design-time services from provider 'Microsoft.EntityFrameworkCore.Sqlite'.
    Finding design-time services referenced by assembly 'HelloWorld'.
    No referenced design-time services were found.
    Finding IDesignTimeServices implementations in assembly 'HelloWorld'...
    No design-time services were found.
    Migrating using database 'main' on server 'blogging.db'.
    Opening connection to database 'main' on server 'blogging.db'.
    Opened connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executed DbCommand (33ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Opening connection to database 'main' on server 'blogging.db'.
    Opened connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
    Executed DbCommand (9ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
    Closing connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Closed connection to database 'main' on server 'blogging.db'.
    Opening connection to database 'main' on server 'blogging.db'.
    Opened connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Opening connection to database 'main' on server 'blogging.db'.
    Opened connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
    Closing connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Closed connection to database 'main' on server 'blogging.db'.
    Opening connection to database 'main' on server 'blogging.db'.
    Opened connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    SELECT "MigrationId", "ProductVersion"
    FROM "__EFMigrationsHistory"
    ORDER BY "MigrationId";
    Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    SELECT "MigrationId", "ProductVersion"
    FROM "__EFMigrationsHistory"
    ORDER BY "MigrationId";
    Closing connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Closed connection to database 'main' on server 'blogging.db'.
    A data reader was disposed.
    Applying migration '20180624040354_InitialIdentity'.
    Opening connection to database 'main' on server 'blogging.db'.
    Opened connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    PRAGMA foreign_keys=ON;
    Beginning transaction with isolation level 'Serializable'.
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetRoles" (
        "Id" TEXT NOT NULL CONSTRAINT "PK_AspNetRoles" PRIMARY KEY,
        "Name" TEXT NULL,
        "NormalizedName" TEXT NULL,
        "ConcurrencyStamp" TEXT NULL
    );
    Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetRoles" (
        "Id" TEXT NOT NULL CONSTRAINT "PK_AspNetRoles" PRIMARY KEY,
        "Name" TEXT NULL,
        "NormalizedName" TEXT NULL,
        "ConcurrencyStamp" TEXT NULL
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUsers" (
        "Id" TEXT NOT NULL CONSTRAINT "PK_AspNetUsers" PRIMARY KEY,
        "UserName" TEXT NULL,
        "NormalizedUserName" TEXT NULL,
        "Email" TEXT NULL,
        "NormalizedEmail" TEXT NULL,
        "EmailConfirmed" INTEGER NOT NULL,
        "PasswordHash" TEXT NULL,
        "SecurityStamp" TEXT NULL,
        "ConcurrencyStamp" TEXT NULL,
        "PhoneNumber" TEXT NULL,
        "PhoneNumberConfirmed" INTEGER NOT NULL,
        "TwoFactorEnabled" INTEGER NOT NULL,
        "LockoutEnd" TEXT NULL,
        "LockoutEnabled" INTEGER NOT NULL,
        "AccessFailedCount" INTEGER NOT NULL
    );
    Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUsers" (
        "Id" TEXT NOT NULL CONSTRAINT "PK_AspNetUsers" PRIMARY KEY,
        "UserName" TEXT NULL,
        "NormalizedUserName" TEXT NULL,
        "Email" TEXT NULL,
        "NormalizedEmail" TEXT NULL,
        "EmailConfirmed" INTEGER NOT NULL,
        "PasswordHash" TEXT NULL,
        "SecurityStamp" TEXT NULL,
        "ConcurrencyStamp" TEXT NULL,
        "PhoneNumber" TEXT NULL,
        "PhoneNumberConfirmed" INTEGER NOT NULL,
        "TwoFactorEnabled" INTEGER NOT NULL,
        "LockoutEnd" TEXT NULL,
        "LockoutEnabled" INTEGER NOT NULL,
        "AccessFailedCount" INTEGER NOT NULL
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetRoleClaims" (
        "Id" INTEGER NOT NULL CONSTRAINT "PK_AspNetRoleClaims" PRIMARY KEY AUTOINCREMENT,
        "RoleId" TEXT NOT NULL,
        "ClaimType" TEXT NULL,
        "ClaimValue" TEXT NULL,
        CONSTRAINT "FK_AspNetRoleClaims_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE
    );
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetRoleClaims" (
        "Id" INTEGER NOT NULL CONSTRAINT "PK_AspNetRoleClaims" PRIMARY KEY AUTOINCREMENT,
        "RoleId" TEXT NOT NULL,
        "ClaimType" TEXT NULL,
        "ClaimValue" TEXT NULL,
        CONSTRAINT "FK_AspNetRoleClaims_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserClaims" (
        "Id" INTEGER NOT NULL CONSTRAINT "PK_AspNetUserClaims" PRIMARY KEY AUTOINCREMENT,
        "UserId" TEXT NOT NULL,
        "ClaimType" TEXT NULL,
        "ClaimValue" TEXT NULL,
        CONSTRAINT "FK_AspNetUserClaims_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserClaims" (
        "Id" INTEGER NOT NULL CONSTRAINT "PK_AspNetUserClaims" PRIMARY KEY AUTOINCREMENT,
        "UserId" TEXT NOT NULL,
        "ClaimType" TEXT NULL,
        "ClaimValue" TEXT NULL,
        CONSTRAINT "FK_AspNetUserClaims_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserLogins" (
        "LoginProvider" TEXT NOT NULL,
        "ProviderKey" TEXT NOT NULL,
        "ProviderDisplayName" TEXT NULL,
        "UserId" TEXT NOT NULL,
        CONSTRAINT "PK_AspNetUserLogins" PRIMARY KEY ("LoginProvider", "ProviderKey"),
        CONSTRAINT "FK_AspNetUserLogins_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserLogins" (
        "LoginProvider" TEXT NOT NULL,
        "ProviderKey" TEXT NOT NULL,
        "ProviderDisplayName" TEXT NULL,
        "UserId" TEXT NOT NULL,
        CONSTRAINT "PK_AspNetUserLogins" PRIMARY KEY ("LoginProvider", "ProviderKey"),
        CONSTRAINT "FK_AspNetUserLogins_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserRoles" (
        "UserId" TEXT NOT NULL,
        "RoleId" TEXT NOT NULL,
        CONSTRAINT "PK_AspNetUserRoles" PRIMARY KEY ("UserId", "RoleId"),
        CONSTRAINT "FK_AspNetUserRoles_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE,
        CONSTRAINT "FK_AspNetUserRoles_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserRoles" (
        "UserId" TEXT NOT NULL,
        "RoleId" TEXT NOT NULL,
        CONSTRAINT "PK_AspNetUserRoles" PRIMARY KEY ("UserId", "RoleId"),
        CONSTRAINT "FK_AspNetUserRoles_AspNetRoles_RoleId" FOREIGN KEY ("RoleId") REFERENCES "AspNetRoles" ("Id") ON DELETE CASCADE,
        CONSTRAINT "FK_AspNetUserRoles_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserTokens" (
        "UserId" TEXT NOT NULL,
        "LoginProvider" TEXT NOT NULL,
        "Name" TEXT NOT NULL,
        "Value" TEXT NULL,
        CONSTRAINT "PK_AspNetUserTokens" PRIMARY KEY ("UserId", "LoginProvider", "Name"),
        CONSTRAINT "FK_AspNetUserTokens_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE TABLE "AspNetUserTokens" (
        "UserId" TEXT NOT NULL,
        "LoginProvider" TEXT NOT NULL,
        "Name" TEXT NOT NULL,
        "Value" TEXT NULL,
        CONSTRAINT "PK_AspNetUserTokens" PRIMARY KEY ("UserId", "LoginProvider", "Name"),
        CONSTRAINT "FK_AspNetUserTokens_AspNetUsers_UserId" FOREIGN KEY ("UserId") REFERENCES "AspNetUsers" ("Id") ON DELETE CASCADE
    );
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetRoleClaims_RoleId" ON "AspNetRoleClaims" ("RoleId");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetRoleClaims_RoleId" ON "AspNetRoleClaims" ("RoleId");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE UNIQUE INDEX "RoleNameIndex" ON "AspNetRoles" ("NormalizedName");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE UNIQUE INDEX "RoleNameIndex" ON "AspNetRoles" ("NormalizedName");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetUserClaims_UserId" ON "AspNetUserClaims" ("UserId");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetUserClaims_UserId" ON "AspNetUserClaims" ("UserId");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetUserLogins_UserId" ON "AspNetUserLogins" ("UserId");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetUserLogins_UserId" ON "AspNetUserLogins" ("UserId");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetUserRoles_RoleId" ON "AspNetUserRoles" ("RoleId");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "IX_AspNetUserRoles_RoleId" ON "AspNetUserRoles" ("RoleId");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "EmailIndex" ON "AspNetUsers" ("NormalizedEmail");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE INDEX "EmailIndex" ON "AspNetUsers" ("NormalizedEmail");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE UNIQUE INDEX "UserNameIndex" ON "AspNetUsers" ("NormalizedUserName");
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    CREATE UNIQUE INDEX "UserNameIndex" ON "AspNetUsers" ("NormalizedUserName");
    Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
    INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
    VALUES ('20180624040354_InitialIdentity', '2.1.1-rtm-30846');
    Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
    INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
    VALUES ('20180624040354_InitialIdentity', '2.1.1-rtm-30846');
    Committing transaction.
    Disposing transaction.
    Closing connection to database 'main' on server '/Users/yufei/Developer/aspnetcore/HelloWorld/HelloWorld/blogging.db'.
    Closed connection to database 'main' on server 'blogging.db'.
    'HelloWorldDBContext' disposed.
    Done.
    

    输出日志很长,大概的意思就是执行成功了

使用 SQLite Studio 可以看到我们的 blogging.db 中已经有了表 Employees ,且有两个字段

可以看到多了很多的表

到此,Identity 数据就迁移成功了

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
SpringCloud迁移至EDAS微服务——Series2:在 ECS 集群中部署 Web 应用
SpringCloud迁移至EDAS微服务——Series2:在 ECS 集群中部署 Web 应用
1707 0
EntityFramework 数据操作
EntityFramework 4.3 数据操作   using (TestEntities te = new TestEntities()) { //增加数据 //Table01 t01 = new Table01(); //t01.
626 0
.NET数据库编程求索之路--11.一些思考
11.一些思考   (1)分层不一定都分为不同的Project,也可以是分为不同的目录(如MVC中的Controllers和Models目录),甚至统一的后缀也是一种分层的方法(如10中划分输入验证层时使用.validater.cs后缀),分层是逻辑概念,不需要与物理概念严格对应。
748 0
.NET数据库编程求索之路--10.使用EF实现(划分输入验证层)
10.使用EF实现(划分输入验证层) 注:使用partial类来实现输入验证逻辑的分层。   源码下载: /Files/SummerRain/NetDbDevRoad/a使用EF实现4划分输入验证层.
576 0
【转】BarTender与ASP.NET的集成小结(条码标签打印编程)
话说自从上次发了篇NHibernate的资料后,好久没有写东西了,半年来一直在忙一个项目,做完项目后,发现很多东西虽然当时做了,懂了,但是很快就会模糊了,于是又再想起总结的重要性~~没啥地方好放资料的,放在博客园也是一个不错的选择~~   本人也是新手,写的不好的地方,请多原谅。
1878 0
.NET数据库编程求索之路--7.使用ADO.NET实现(工厂模式-实现多数据库切换)(1)
7.使用ADO.NET实现(工厂模式-实现多数据库切换)(1)     7.1 解决方案框架 解决方案(.sln)包含以下几个项目: (1)类库项目HomeShop.DbUtility,数据访问实用工具; (2)类库项目HomeShop.
744 0
.NET数据库编程求索之路--7.使用ADO.NET实现(工厂模式-实现多数据库切换)(2)
7.使用ADO.NET实现(工厂模式-实现多数据库切换)(2)     7.3 数据访问层工厂HomeShop.DALFactory      1 using System; 2 using System.
891 0
在Entity Framework中重用现有的数据库连接字符串
本文转载:http://www.cnblogs.com/dudu/archive/2011/01/29/entity_framework_connection_string.html 如果EF在使用实体模型时候,即model first 和db first 时候,则 Entity Framework使用的连接字符串与ADO.NET是不同的,见下图: 相比于ADO.NET,Entity Framework的连接字符串不仅要存放metadata配置信息,还要存放完整的数据库连接字符串(上图中的"provider connection string"部分)。
874 0
.NET数据库编程求索之路--7.使用ADO.NET实现(工厂模式-实现多数据库切换)(4)
7.使用ADO.NET实现(工厂模式-实现多数据库切换)(4) 7.7 业务逻辑层HomeShop.BLL OrderBiz.cs View Code  1 using System; 2 using System.
775 0
+关注
杰克.陈
一个安静的程序猿~
10427
文章
2
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载