MVC5播种问题
MVC5 Problems with planting seeds
关于这个问题:MVC 5 Seed Users and Roles 我尝试设置默认用户种子。
我在 Configuration.cs 中尝试的方式是:
var passwordHash = new PasswordHasher();
string defaultPassword = passwordHash.HashPassword("SuperPassword");
context.Users.AddOrUpdate(u => u.UserName,
new ApplicationUser
{
UserName = "admin@project.loc",
Email = "admin@project.loc",
PasswordHash = defaultPassword
});
但是现在遇到无法使用命令迁移数据库的问题。不幸的是,对其他人有用的解决方案对我没有帮助。
当我尝试更新数据库时出现错误:
There is already an object named 'AspNetRoles' in the database.
我尝试使用 Add-Migration <name> -IgnoreChanges
但出现错误,迁移仍在等待中。
早些时候我尝试为我的两个上下文启用迁移,但有一个我收到此错误消息:
Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
其他上下文的启用迁移刚刚用自定义种子覆盖了我的 Configuration.cs。
编辑Up和Down方法的提示对我很有帮助,谢谢!
不知道我可以在这里编辑操作。
关于这个问题:MVC 5 Seed Users and Roles 我尝试设置默认用户种子。 我在 Configuration.cs 中尝试的方式是:
var passwordHash = new PasswordHasher();
string defaultPassword = passwordHash.HashPassword("SuperPassword");
context.Users.AddOrUpdate(u => u.UserName,
new ApplicationUser
{
UserName = "admin@project.loc",
Email = "admin@project.loc",
PasswordHash = defaultPassword
});
但是现在遇到无法使用命令迁移数据库的问题。不幸的是,对其他人有用的解决方案对我没有帮助。
当我尝试更新数据库时出现错误:
There is already an object named 'AspNetRoles' in the database.
我尝试使用 Add-Migration <name> -IgnoreChanges
但出现错误,迁移仍在等待中。
早些时候我尝试为我的两个上下文启用迁移,但有一个我收到此错误消息:
Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
其他上下文的启用迁移刚刚用自定义种子覆盖了我的 Configuration.cs。
编辑Up和Down方法的提示对我很有帮助,谢谢! 不知道我可以在这里编辑操作。