简体   繁体   English

实体框架核心更新-数据库特定的迁移没有权限错误

[英]Entity Framework Core Update-database specific migration gives no permission error

I have created a migration earlier and applied to the database. 我已经创建了一个迁移,并将其应用于数据库。 I have had the table in the SQL Server database. 我在SQL Server数据库中有该表。 Then I delete the table using SQL Server. 然后,我使用SQL Server删除表。 So the table is not in the database anymore. 因此,该表不再位于数据库中。

After that, I wanted to re-apply the same migrations using dotnet ef database update AddScreens . 之后,我想使用dotnet ef database update AddScreens重新应用相同的迁移。 AddScreens is the name of the migration. AddScreens是迁移的名称。

However, running this throws the following error: 但是,运行此操作将引发以下错误:

Cannot find the object "Screens" because it does not exist or you do not have permissions 找不到对象“屏幕”,因为它不存在或您没有权限

I am trying to add Screens table to the SQL Server again using CLI. 我试图再次使用CLI将Screens表添加到SQL Server。 I have tried to create a new migration but this time it gave me a blank migration. 我试图创建一个新的迁移,但这一次它给了我一个空白的迁移。 Any help will be appreciated! 任何帮助将不胜感激!

Have you checked the table __MigrationHistory ? 您检查了__MigrationHistory表吗?

Every Migration you apply is recorded inside this table. 您应用的每个迁移都记录在此表中。 If you have inserted the table with update database eg. 如果您已插入带有更新数据库的表,例如。 the record is inside there and Entity Framework does try to find the table. 记录在其中,而Entity Framework确实会尝试查找表。

You can also check at first for the Migrations: 您也可以首先检查迁移:

Get-Migrations

If you would want to revert a recent migration 如果您想还原最近的迁移

Update-Database -TargetMigration:"<name>"

is the way to go. 是要走的路。 I think currently your database schema and EF is missmatched. 我认为目前您的数据库架构和EF不匹配。

You could manually restore the table and check if the database is ok again or re-create the whole schema (but this way you loese the data). 您可以手动还原表并检查数据库是否还可以,或者重新创建整个架构(但是通过这种方式您可以删除数据)。

Sadly I do not know how to check with PMC the schema, by code it is: 可悲的是,我不知道如何使用PMC来检查模式,通过代码可以看到:

if(context.Database.CompatibleWithModel(true))
..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM