gpt4 book ai didi

c# - Mysql 更新数据库 System.FormatException

转载 作者:行者123 更新时间:2023-11-29 15:44:53 24 4
gpt4 key购买 nike

我在尝试将更新数据库迁移功能与 EntityFramework 结合使用时收到错误。我经常使用这个功能,没有出现任何问题。这是我的 2 个问题类:

public class Produit
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int Upc { get; set; }

public int? BinId { get; set; }
[ForeignKey("BinId")]
public Bin Bin { get; set; }

}

public class Bin
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int NoBin { get; set; }
public virtual ICollection<Produit> Produits { get; set; }
}

错误:

    PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201907231929105_Initial].
Applying explicit migration: 201907231929105_Initial.
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDouble(String value)
at MySql.Data.EntityFramework.MySqlMigrationSqlGenerator.Generate(CreateIndexOperation op)
at MySql.Data.EntityFramework.MySqlMigrationSqlGenerator.<.ctor>b__22_4(MigrationOperation op)
at MySql.Data.EntityFramework.MySqlMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
at System.Data.Entity.Migrations.DbMigrator.GenerateStatements(IList`1 operations, String migrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.GenerateStatements(IList`1 operations, String migrationId)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClasse.<Update>b__d()
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Input string was not in a correct format.

enable-migrations 有效,add-migration 也有效。

我使用的包:MySql.Data.EntityFramework (8.0.17.0)MySql.Data (8.0.17.0)

最佳答案

这看起来与 bug 92561 相同在 MySql.Data.EntityFramework 中,这是由于在非美国英语语言环境中运行引起的。

作为解决方法,您可以尝试将计算机的区域设置切换为美国英语来运行迁移。

或者,尝试切换到 Pomelo.EntityFrameworkCore.MySql ,EF Core for MySQL 的 OSS 实现;很多人报告说它比 Oracle 的版本错误更少。

关于c# - Mysql 更新数据库 System.FormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57182886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com