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