0
respostas

Erro Specified key was too long; max key length is 3072 bytes

Estou com esse erro quando faço update do banco de dados, como posso resolver ?

using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using System;

namespace UsuariosApi.Data { public class UserDbContext : IdentityDbContext<IdentityUser, IdentityRole, int> { private IConfiguration _configuration;

    public UserDbContext(DbContextOptions<UserDbContext> opt, IConfiguration configuration) : base(opt)
    {
        _configuration = configuration;
    }
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        IdentityUser<int> admin = new IdentityUser<int>
        {
            UserName = "admin",
            NormalizedUserName = "ADMIN",
            Email = "admin@admin.com.br",
            NormalizedEmail = "ADMIN@ADMIN.COM.BR",
            EmailConfirmed = true,
            SecurityStamp = Guid.NewGuid().ToString(),
            Id = 99999
        };

        PasswordHasher<IdentityUser<int>> passwordHasher = new PasswordHasher<IdentityUser<int>>();

        admin.PasswordHash = passwordHasher.HashPassword(admin,
            _configuration.GetValue<String>("admininfo:password"));

        builder.Entity<IdentityUser<int>>().HasData(admin);

        builder.Entity<IdentityRole<int>>().HasData(
            new IdentityRole<int>{Id = 99999,  Name = "admin", NormalizedName = "ADMIN",}
            );
        builder.Entity<IdentityRole<int>>().HasData(
            new IdentityRole<int> { Id = 99997, Name = "regular", NormalizedName = "REGULAR", }
            );

        builder.Entity<IdentityUserRole<int>>().HasData(
            new IdentityUserRole<int> { RoleId = 99999, UserId = 99999 }
            );


    }

}

}