如何使用EF6重新創建數據庫?數據庫沒有在第一時間創建
我已經嘗試了以下兩篇文章,但是,我不知道爲什麼它不工作,並得到相同的錯誤。
- How do I generate an EF6 database with migrations enabled, without using update-database?
- Migrations is enabled for context ''but the database does not exist or contains no mapped tables
我已經出版了我的Web服務器上的樣品。我正在使用Sql Server 2012 Express DBMS。
當我創建我的應用程序並將它發佈到Web服務器上時,它工作正常。它已經自動創建了數據庫。之後,我對ApplicationDBContext
進行了一些更改,並在IdentityModes(ApplicationUser)
中添加了一些屬性。然後我已經遷移了我的本地IIS Express上的數據庫,它工作正常。然後我試圖再次在Web服務器上發佈我的示例,但這次它顯示錯誤。
Migrations is enabled for context 'ApplicationDbContext' but the database does
not exist or contains no mapped tables. Use Migrations to create the database
and its tables, for example by running the 'Update-Database' command from the
Package Manager Console.
我已經刪除了Web服務器上的數據庫,然後再次嘗試。但是,我仍然面臨同樣的錯誤。現在,有一個沒有表的空數據庫。
應用程序正在用戶註冊中創建數據庫。
我也看過這post,並試圖打電話dbContext.Database.Initialize(true);
和((IObjectContextAdapter)myContext).ObjectContext.CreateDatabase()
方法,但是,它仍然無法正常工作。
謝謝克里斯,現在,它的工作國王。當啓用「遷移」功能時,數據庫不會被創建。所以,我已經從項目中刪除了'Migration'文件夾,並從數據庫中刪除了'_MigrationHistory'表格,然後我再次發佈了它。然後再試一次,它像魔術一樣工作。再次感謝克里斯我試圖解決它自2天以來。 – Shell 2014-09-23 03:22:36