我正在使用Entity Framework开发解决方案。我使用Code First Work Flow通过创建迁移来更新我的数据库。一切正常,现在我想部署到生产。我使用了Package Manager Console中的Update-Database -script -SourceMigration:InitialModel
来生成我想在生产数据库上运行的数据库脚本。这是生成的脚本文件的一部分:
CREATE TABLE [dbo].[Projects] (
[Id] [int] NOT NULL IDENTITY,
[Title] [nvarchar](max),
[OwnerId] [int] NOT NULL,
[StartDate] [datetime] NOT NULL,
[EndDate] [datetime] NOT NULL,
[ProjectStatus] [int] NOT NULL,
CONSTRAINT [PK_dbo.Projects] PRIMARY KEY ([Id])
)
INSERT [dbo].[__MigrationHistory]([MigrationId], [ContextKey], [Model],
[ProductVersion])
VALUES (N'201711231319470_AddProjectTableToDB',
N'ErdisERP_AmpleAdminTheme.Migrations.Configuration', A Large Random
String, N'6.1.3-40302')
More SQL codes...
以下是产生的错误Msg 208, Level 16, State 1, Line 10
Invalid object name 'dbo.__MigrationHistory'.
P.S:我刚刚开始使用ASP.NET MVC5。我会感激任何指针。谢谢。
答案 0 :(得分:0)
您似乎没有__MigrationHistory表。当您使用-SourceMigration:InitialModel
EF时,将使用它作为起点。如果您想告诉EF使用空白数据库作为起点,请使用$InitialDatabase
,其中还包含用于创建__MigrationHistory的代码:
Update-Database -Script -SourceMigration: $InitialDatabase