【发布时间】:2020-11-08 21:33:10
【问题描述】:
我有这样的 DB 编码:
public class DBModel : DbContext
{
public DBModel()
: base("name=DBModel")
{
}
public virtual DbSet<Entry> Entries{ get; set; }
}
public class Entry
{
[Key]
public int Id { get; set; }
public DateTime EntryDate { get; set; }
public string EntryContent { get; set; }
public virtual Alarm Alarm { get; set; }
}
public class Alarm
{
[Key]
public int AlarmId { get; set; }
public DateTime AlarmDate { get; set; }
public bool Enabled { get; set; }
}
当我尝试更新数据库时,它以带有此堆栈的 FormatException 结束:
System.FormatException: Nieprawidłowy format ciągu wejściowego.
w System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
w System.Convert.ToDouble(String value)
w MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(CreateIndexOperation op)
w MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
w System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
w System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading)
w System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading)
w System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
w System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
w System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
w System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
w System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
w System.Data.Entity.Infrastructure.Design.Executor.Update.<>c__DisplayClass0_0.<.ctor>b__0()
w System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)
EF 框架版本:6.4.4 MySQL服务器版本:8.0.18 MySQL 插件:
- MySQL.Data v6.10.9
- MySQL.Data v6.10.9
如何解决?
【问题讨论】:
-
在破坏更新数据库之前是否添加了迁移?
标签: c# mysql entity-framework ef-code-first