[英]update-database not working in Code first
I am using entity framework and Codefirst to create a Stored procedure. 我正在使用实体框架和Codefirst创建存储过程。 As I reed, we should do some steps in package manager to create SP.
正如我所言,我们应该在程序包管理器中执行一些步骤来创建SP。
1 - enable migration 1-启用迁移
2- add-migration MYclass 2-添加迁移MYclass
3- update-database 3-更新数据库
and in Myclass(new created)
I write my SP code in UP() method to create SP. 在
Myclass(new created)
我在UP()方法中编写我的SP代码以创建SP。 works fine!! 工作正常!! BUT when I change SP and run update-database again it does not work and I need to do another add-migration command to create new MYclass2.
但是,当我更改SP并再次运行update-database时,它不起作用,我需要执行另一个add-migration命令来创建新的MYclass2。 Is that right?
那正确吗? I mean every time I should write add-migration?
我的意思是每次我应该写添加迁移?
this is mycode 这是我的代码
public override void Up()
{
Sql(@"Create procedure testSp
as
select std.Id as stdName, std.Name as MajorName, mj.Name from dbo.Students as std
inner join dbo.Majors as mj on std.Id = mj.Id
");
}
public override void Down()
{
Sql("drop procedure testSp");
}
when I run update-database again the result is "No pending explicit migration"
当我再次运行update-database时,结果是
"No pending explicit migration"
even if I change the SQL query to "Alter procedure...." it does not work , no change happens. 即使我将SQL查询更改为“ Alter procedure ....”,它也不起作用,也不会发生任何更改。 thanks
谢谢
EDITED EDITED
consider this scenario, I want to change my SP name(just an example) so I need to change the query to "Alter store procedure tespSP2 ..." or any other change, should I run add-migration again?? 考虑这种情况,我想更改我的SP名称(仅作为示例),因此我需要将查询更改为“ Alter store procedure tespSP2 ...”或任何其他更改,是否应该再次运行add-migration? or update-database is supposed to do it??
还是应该更新数据库?
in entity framework migrations added to a _migrationHistory table, you can delete the last row of this table [it's not recommended] 在添加到_migrationHistory表中的实体框架迁移中,您可以删除此表的最后一行[不推荐]
or you can use rollback/undo command 或者您可以使用rollback / undo命令
Update-Database -TargetMigration:MigrationsName
then use update-database -force
然后使用
update-database -force
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.