Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Mac OSX、ASP.NET和mySQL-密钥长度错误_C#_Mysql_.net_Asp.net Mvc_Asp.net Core - Fatal编程技术网

C# Mac OSX、ASP.NET和mySQL-密钥长度错误

C# Mac OSX、ASP.NET和mySQL-密钥长度错误,c#,mysql,.net,asp.net-mvc,asp.net-core,C#,Mysql,.net,Asp.net Mvc,Asp.net Core,我对ASP.Net非常陌生,我正在尝试编写一个基本的应用程序,以便在web浏览器中显示MySQL数据库中的一些数据 我认为我试图创建的实体的主键被标记为太大。当我查看连接到的数据库时,我可以看到一个新的模式出现。如果我再次点击run,页面将被加载,但是在第一次运行时(在创建模式之前),我得到了一个错误,我已经在这个问题的底部包含了这个错误 如果在下面的代码中,我取消对entity.HasKey行的注释,并添加一行以将属性更改为适当的大小,则会出现相同的错误 尝试在模型上放置[Key]会产生相同的

我对ASP.Net非常陌生,我正在尝试编写一个基本的应用程序,以便在web浏览器中显示MySQL数据库中的一些数据

我认为我试图创建的实体的主键被标记为太大。当我查看连接到的数据库时,我可以看到一个新的模式出现。如果我再次点击run,页面将被加载,但是在第一次运行时(在创建模式之前),我得到了一个错误,我已经在这个问题的底部包含了这个错误

如果在下面的代码中,我取消对entity.HasKey行的注释,并添加一行以将属性更改为适当的大小,则会出现相同的错误

尝试在模型上放置[Key]会产生相同的错误

using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using aspNet_Sep_3_b.Models;
using aspNet_Sep_3_b;

namespace aspNet_Sep_3_b.DAL
{
    public class mysqlContext : IdentityDbContext<ApplicationUser> //iddbcontext of type appuser
    {
        public virtual DbSet<Person> Person { get; set; }

        public mysqlContext(DbContextOptions<mysqlContext> options) :base(options)
        {
            this.Database.EnsureCreated();//Any time we run this project, we need to create the database. So any time we change the database, we'll need to drop it, and create it with a new structure.

        }

        public mysqlContext()
        {
            this.Database.EnsureCreated();
        }

        protected override void OnModelCreating(ModelBuilder builder) //What is this?
        {
            base.OnModelCreating(builder);
            builder.Entity<ApplicationUser>().Property(u => u.Id).HasMaxLength(36);

            builder.Entity<Person>(entity =>
            {

                entity.Property(e => e.PersonId).HasColumnType("SMALLINT");
                //entity.HasKey(e => e.PersonId);
                entity.Property(e => e.PersonName).IsRequired().HasMaxLength(36);


            });



            //builder.Entity<Person>().Property(e => e.PersonID).HasMaxLength(36);
            //builder.Entity<Person>().Property(e => e.PersonName).HasMaxLength(36);

        }

        //Program myProgram = new Program();
    }
}

使用系统;
使用Microsoft.EntityFrameworkCore;
使用Microsoft.AspNetCore.Identity.EntityFrameworkCore;
使用aspNet_Sep_3_b.模型;
使用aspNet_Sep_3_b;
名称空间aspNet_Sep_3_b.DAL
{
公共类mysqlContext:IdentityDbContext//appuser类型的iddbcontext
{
公共虚拟数据库集Person{get;set;}
公共mysqlContext(DbContextOptions):基本(选项)
{
this.Database.EnsureCreated();//无论何时运行此项目,都需要创建数据库。因此,无论何时更改数据库,都需要删除它,并使用新结构创建它。
}
公共mysqlContext()
{
this.Database.recreated();
}
模型创建时受保护的覆盖无效(ModelBuilder)//这是什么?
{
基于模型创建(生成器);
builder.Entity().Property(u=>u.Id).HasMaxLength(36);
builder.Entity(Entity=>
{
entity.Property(e=>e.PersonId).HasColumnType(“SMALLINT”);
//entity.HasKey(e=>e.PersonId);
entity.Property(e=>e.PersonName).IsRequired().HasMaxLength(36);
});
//builder.Entity().Property(e=>e.PersonID).HasMaxLength(36);
//builder.Entity().Property(e=>e.PersonName).HasMaxLength(36);
}
//程序myProgram=新程序();
}
}
错误:




    MySqlException: Specified key was too long; max key length is 3072 bytes

MySql.Data.MySqlClient.MySqlStream.ReadPacket()
MySql.Data.MySqlClient.NativeDriver.GetResult(ref int affectedRow, ref long insertedId)
MySql.Data.MySqlClient.Driver.NextResult(int statementId, bool force)
MySql.Data.MySqlClient.MySqlDataReader.NextResult()
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary<string, object> parameterValues)
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary<string, object> parameterValues)
Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary<string, object> parameterValues)
Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable<MigrationCommand> migrationCommands, IRelationalConnection connection)
Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTables()
Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreated()
Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()
aspNet_Sep_3_b.DAL.mysqlContext..ctor(DbContextOptions<mysqlContext> options) in mysqlContext.cs

                this.Database.EnsureCreated();//Any time we run this project, we need to create the database. So any time we change the database, we'll need to drop it, and create it with a new structure.

Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<TArgument, TResult>.VisitCallSite(IServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<TArgument, TResult>.VisitCallSite(IServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
lambda_method(Closure , IServiceProvider , object[] )
Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider+<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider+<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)


MySqlException:指定的密钥太长;最大密钥长度为3072字节
MySql.Data.MySqlClient.MySqlStream.ReadPacket()
MySql.Data.MySqlClient.NativeDriver.GetResult(ref int affectedRow,ref long insertedId)
MySql.Data.MySqlClient.Driver.NextResult(int statementId,bool force)
MySql.Data.MySqlClient.MySqlDataReader.NextResult()
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior)
MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection连接、DbCommandMethod executeMethod、iRadonlyDictionary参数值)
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteOnQuery(IRelationalConnection连接,iRelationalDYDictionary参数值)
Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.ExecuteOnQuery(IRelationalConnection连接,IReadOnlyDictionary参数值)
Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecutionQuery(IEnumerable migrationCommands,IRelationalConnection)
Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.CreateTables()
Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreated()
Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Rescreated()文件
mysqlContext.cs中的aspNet_Sep_3_b.DAL.mysqlContext..ctor(DbContextOptions选项)
this.Database.recreated()//任何时候我们运行这个项目,我们都需要创建数据库。因此,每当我们更改数据库时,我们都需要删除它,并使用新结构创建它。
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite ConstructorCallSite,ServiceProviderEngineScope作用域)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite,Target参数)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite ScopedCallSite,ServiceProviderEngineScope作用域)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite,Target参数)
Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+c\u DisplayClass1\u 0.b\u 0(ServiceProviderEngineScope作用域)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(类型serviceType,ServiceProviderEngineScope ServiceProviderEngineScope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(类型serviceType)
Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp,类型类型,类型requiredBy,bool isDefaultParameterRequired)
lambda_方法(闭包、IServiceProvider、对象[])
Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider+c__显示类4_0.b__0(ControllerContext ControllerContext)
Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider+c_uuuDisplayClass5_0.g_uuCreateController | 0(ControllerContext ControllerContext)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref状态Next、ref范围、ref对象状态、ref bool已完成)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State Next、ref Scope Scope、ref object State、ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(H
builder.Entity<ApplicationUser>(entity => entity.Property
                    (p => p.Id).HasMaxLength(128));
            builder.Entity<ApplicationUser>(entity => entity.Property
                    (p => p.NormalizedEmail).HasMaxLength(128));
            builder.Entity<ApplicationUser>(entity => entity.Property
                    (p => p.NormalizedUserName).HasMaxLength(128));

            builder.Entity<IdentityRole>(entity => entity.Property
                    (p => p.Id).HasMaxLength(128));
            builder.Entity<IdentityRole>(entity => entity.Property
                    (p => p.NormalizedName).HasMaxLength(128));

            builder.Entity<IdentityUserToken<string>>(entity => entity.Property
                    (p => p.LoginProvider).HasMaxLength(128));
            builder.Entity<IdentityUserToken<string>>(entity => entity.Property
                    (p => p.UserId).HasMaxLength(128));
            builder.Entity<IdentityUserToken<string>>(entity => entity.Property
                    (p => p.Name).HasMaxLength(128));

            builder.Entity<IdentityUserRole<string>>(entity => entity.Property
                    (p => p.UserId).HasMaxLength(128));
            builder.Entity<IdentityUserRole<string>>(entity => entity.Property
                    (p => p.RoleId).HasMaxLength(128));


            builder.Entity<IdentityUserLogin<string>>(entity => entity.Property
                    (p => p.LoginProvider).HasMaxLength(128));
            builder.Entity<IdentityUserLogin<string>>(entity => entity.Property
                    (p => p.ProviderKey).HasMaxLength(128));
            builder.Entity<IdentityUserLogin<string>>(entity => entity.Property
                    (p => p.UserId).HasMaxLength(128));

            builder.Entity<IdentityUserClaim<string>>(entity => entity.Property
                    (p => p.Id).HasMaxLength(128));
            builder.Entity<IdentityUserClaim<string>>(entity => entity.Property
                    (p => p.UserId).HasMaxLength(128));

            builder.Entity<IdentityRoleClaim<string>>(entity => entity.Property
                    (p => p.Id).HasMaxLength(128));
            builder.Entity<IdentityRoleClaim<string>>(entity => entity.Property
                    (p => p.RoleId).HasMaxLength(128));