首页 > 解决方案 > 将 ASP.NET MVC MySql db 迁移到 PLESK

问题描述

我已将我的 Asp.NET 项目发布到 Plesk,它已成功完成。现在我需要使用 PM 更新数据库,但它会为“ASPNETROLES”创建表,然后引发异常。

指定的密钥太长;最大密钥长度为 767 字节

我找到了以下解决方案,但没有一个有效:

https://bugs.mysql.com/bug.php?id=81817

指定的密钥太长;实体框架 6 中的最大密钥长度为 767 字节 Mysql 错误

我尝试了以下代码但失败了:

[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class AppIdentityDbContext : IdentityDbContext<ApplicationUser>
{
    public AppIdentityDbContext() : base("myConnection")
    {

    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Entity<HistoryRow>().HasKey<string>(h => h.MigrationId);
        modelBuilder.Entity<HistoryRow>().Property(h => h.MigrationId).HasMaxLength(100).IsRequired();
        modelBuilder.Entity<HistoryRow>().Property(h => h.ContextKey).HasMaxLength(200).IsRequired();
        modelBuilder.Entity<ApplicationUser>().Property(u => u.Id).HasMaxLength(128);
        modelBuilder.Entity<ApplicationUser>().Property(u => u.UserName).HasMaxLength(128);
        modelBuilder.Entity<ApplicationUser>().Property(u => u.Email).HasMaxLength(128);
        modelBuilder.Entity<IdentityRole>().Property(r => r.Name).HasMaxLength(128);

}

它应该创建所有 ASPNET 表,还应该将主键设置为自动递增。

有人可以分享在 Plesk 上部署的指南吗?

标签: mysqlentity-frameworkdatabase-migrationproduction-environment

解决方案


推荐阅读