一、执行 Enable-Migrations,
如果执行失败,重新安装EF,或者更新Nuget
二、更改实体
例如:
此时的theme表:
![2789632-b6a92eccab98fb79.png](https://i-blog.csdnimg.cn/blog_migrate/d75dac2b336661f76dcc395b22b202ac.webp?x-image-process=image/format,png)
在实体中添加一个测试字段
![2789632-e1bd2ed5995d6754.png](https://i-blog.csdnimg.cn/blog_migrate/82b2c588598dbba26f6d16149d054c71.webp?x-image-process=image/format,png)
三、执行Update-Database -Force
四、查看数据库
![2789632-50ebe33a25b7da12.png](https://i-blog.csdnimg.cn/blog_migrate/88e848209100083ae69ff8c120d55a33.webp?x-image-process=image/format,png)
解释:
如果实体删除字段,更新后数据库也会删除该字段。如果是外界添加字段,不会影响实体。
![2789632-3b18269684ea9294.png](https://i-blog.csdnimg.cn/blog_migrate/968ba340cacfe731cb84448c30f50e60.webp?x-image-process=image/format,png)
公众号.png
如果执行失败,重新安装EF,或者更新Nuget
例如:
此时的theme表:
在实体中添加一个测试字段
解释:
如果实体删除字段,更新后数据库也会删除该字段。如果是外界添加字段,不会影响实体。