只有在没数据库的情况下才初始化种子

This commit is contained in:
liyaobang 2025-03-24 18:41:23 +08:00
parent cb7e216b3a
commit 959a2bf642

View File

@ -21,17 +21,23 @@ namespace DHSoftware.Utils
EnsureDirectoryExists(); EnsureDirectoryExists();
using (var db = GetDatabase()) using (var db = GetDatabase())
{ {
// 创建所有表 // 检查初始化状态(通过检查是否存在系统表)
db.CodeFirst.InitTables( bool isInitialized = db.DbMaintenance.IsAnyTable("RolePermission");
typeof(User),
typeof(Role),
typeof(Permission),
typeof(UserRole),
typeof(RolePermission)
);
// 初始化基础数据 if (!isInitialized)
InitializeSeedData(db); {
// 创建所有表
db.CodeFirst.InitTables(
typeof(User),
typeof(Role),
typeof(Permission),
typeof(UserRole),
typeof(RolePermission)
);
// 初始化基础数据
InitializeSeedData(db);
}
} }
} }