如何使用EF 6.0中的代码优先方法从sql表中删除列? [英] How can we delete a column from sql table by using code first approach in EF 6.0?

查看:147
本文介绍了如何使用EF 6.0中的代码优先方法从sql表中删除列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于错误,如果我想使用代码优先方法从表中删除该列,我现在在数据库中添加了一个列名为doj.

By mistake I've added one column in my database Named as doj now if I want to drop that column from table using code first approach what should I do.

我已经尝试过了.

1-从模型中删除列定义.
2-删除迁移历史记录.
3-添加迁移
4-更新数据库.

1- Removing the column definition from model.
2- Deleted Migration history.
3- Add-migration
4- Update database.

但是它仍然没有反映在数据库中吗?我在哪里弄错了?

But still it is not reflecting in database? Where I made the mistake?

推荐答案

不需要删除迁移历史记录.

Don't need to delete migration history.

只需执行以下步骤

1: Remove properties from the model.
2: Run 'Enable-Migrations' in package manage console.
3: Next Run 'Add-Migration "MigrationsName"'. if any case it is showing 'The project  tesproject failed to build then build project again.
4: Now run 'Update-Database' 

这将对您的代码产生影响.使用 MSDN

It will surly effect on your code. Go with MSDN

这篇关于如何使用EF 6.0中的代码优先方法从sql表中删除列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆