简体   繁体   English

为什么我在运行更新数据库时得到 Object 引用未设置为 object 的实例

[英]Why do I get Object reference not set to an instance of an object when running Update-Database

First time working with entity framework, I've been testing with an in memory database which has been working fine but wanted to start working on a persistent database using sqlite.第一次使用实体框架时,我一直在使用 memory 数据库进行测试,该数据库运行良好,但想开始使用 sqlite 处理持久性数据库。

I've got the model and context created, when I run Add-Migration in the Package Manager Console it seems to work fine but when I then run the Update-Database function I always get a 'Object reference not set to an instance of an object' error but I can't work out why, any help really appreciated, been searching around for a while and can't see anything.我已经创建了 model 并创建了上下文,当我在 Package 管理器控制台中运行 Add-Migration 时,它似乎工作正常,但是当我然后运行更新数据库 ZC1C425268E68385D1AB5074C17A94 的实例时,我总是不设置为object' 错误,但我不知道为什么,任何帮助真的很感激,一直在寻找一段时间,但什么也看不到。

Screenshot of the reported error报错截图

I've got four model classes and the context class so not sure I can include all the code snippets here but happy to if folk think it's needed to get anywhere.我有四个 model 类和上下文 class 所以不确定我可以在这里包含所有代码片段,但如果人们认为它需要到达任何地方,我很高兴。

Thanks.谢谢。

OK so I found out what the issue was.好的,所以我发现了问题所在。 The "Object reference not set to an instance of an object" in this case was due to the fact that I didn't have a reference to Microsoft.EntityFrameworkCore.Sqlite.在这种情况下,“对象引用未设置为对象的实例”是因为我没有对 Microsoft.EntityFrameworkCore.Sqlite 的引用。 I did have a reference to Microsoft.EntityFrameworkCore.Sqlite.Core which is what allowed the project to build OK but apparently this is required for the Update-Database call.我确实引用了 Microsoft.EntityFrameworkCore.Sqlite.Core,这使项目可以正常构建,但显然这是 Update-Database 调用所必需的。

Also for anyone else needing to take a step back and just confirm they aren't going crazy, this is a good website describing what is needed.对于其他需要退后一步并确认他们没有发疯的人来说,这是一个很好的网站,描述了需要什么。 I used this just to confirm everything worked OK and I hadn't missed something (which I obviously had).我用它只是为了确认一切正常并且我没有错过任何东西(我显然有)。

TL:DR - Make sure you have a reference to Microsoft.EntityFrameworkCore.Sqlite TL:DR - 确保您参考了 Microsoft.EntityFrameworkCore.Sqlite

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么会出现错误“对象引用未设置为对象的实例”? - Why do I get the error, “Object reference not set to an instance of an object”? 为什么在尝试连接数据库时出现“对象引用未设置为对象实例”的信息? - Why do I get “Object reference not set to an instance of an object” trying to connect to a database? 在asp.net中更改页面时,为什么会收到“对象引用未设置为对象实例”的信息? - Why do I get “Object reference not set to an instance of an object.” when changing pages in asp.net 为什么我得到“引用未设置到对象的实例? - Why do I get the "reference not set to an instance of an object? 为什么我在自定义OnLoaded事件上得到“对象引用未设置为对象的实例”? - Why do I get a “Object reference not set to an instance of an object” on my custom OnLoaded event? 运行webform时,对象引用未设置为对象错误标志的实例 - Object reference not set to an instance of an object error flags when running webform 运行应用程序时出现“对象引用未设置为对象实例”错误 - “Object reference not set to an instance of an object” error when running app 为什么在这里出现“对象引用未设置为对象的实例”? - Why am I getting “Object reference not set to an instance of an object” here? 为什么我不断收到“对象引用未设置为对象的实例”错误? - Why do I keep getting a "Object Reference not set to an instance of an object" error? 为什么我总是收到“对象引用未设置为对象实例”的信息? - Why I keep getting “Object reference not set to an instance of an object.”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM