实体框架自动迁移现有数据库 [英] Entity Framework Automatic Migrations Existing Database

查看:90
本文介绍了实体框架自动迁移现有数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework 5构建ASP.Net MVC4 Web应用程序.我不得不使用现有的sql server数据库,但也想使用Code First,因此我遵循了本教程

I am building an ASP.Net MVC4 web application with Entity Framework 5. I had to use an existing sql server database but also wanted to use Code First, so I followed this tutorial http://msdn.microsoft.com/en-us/data/jj200620.aspx

我的应用程序通过Entity Framework使用自动迁移.

My application uses automatic migrations with Entity Framework.

我在整个开发阶段使用的sql server版本是2008,但是,在最后一分钟,我被告知数据库需要在sql server 2005上工作.我得到了在sql server 2008中使用的数据库设置(确切的表,属性名称,关系等).但是,通过我的Web配置等设置指向sql server 2005数据库,当我对自己的模型类之一进行更改时,自动迁移不会不行.

The version of sql server I was using throughout the development phase was 2008, however, at the last minute I've been told the database needs to work on sql server 2005. I got the database I was using in sql server 2008 setup (exact tables, property names, relationships etc) on sql server 2005. However, with my web config etc setup to point to the sql server 2005 database, when I make a change to my one of my model classes, the automatic migrations don't work.

我收到以下错误

在 数据库.

There is already an object named 'tblcourseprofessionTarget' in the database.

任何人都可以帮忙吗?

谢谢.

很抱歉,如果我没有添加足够的信息.

Apologies if I haven't added enough information.

推荐答案

伙计们

本文 http://christesene.com/entity-framework-4-3-code-first-with-automatic-migrations/

我必须删除以前的初始迁移类,然后重新创建它.

I had to delete my previous initial migration class, and re-create it.

这篇关于实体框架自动迁移现有数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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