我正在尝试使用适用于 Windows XP 的 powershell 代码在新的 Windows 7 计算机上安装数据库。我能够修复我遇到的大多数问题,但我已经在这个特定问题上卡了几个小时。
我正在尝试更新表键;
# here we need to update the indexes here
# if we are just seeding, dont bother updating, just write the Checksum property
#
if (!$whatif)
{
if (!$seed)
{
# drop all foreign keys before trying to execute the SQL script
for([int] $i=$table.triggers.count-1; $i -ge 0; $i--)
{
$table.triggers[$i].drop()
}
$table.Alter();
trap { $_ | UTD-Write-Sql-Exception }
$db.ExecuteNonQuery($filedata)
}
我收到以下错误。
Source : .Net SqlClient Data Provider
Number : 1776
State : 0
Class : 16
Server : (machine name)
Message : There are no primary or candidate keys in the referenced table 'dbo.PasswordPolicies' that match the referencing column list in the foreign key 'FK_PasswordPolicies_ad_PasswordPolicies'.
Procedure :
LineNumber : 1
Source : .Net SqlClient Data Provider
Number : 1750
State : 0
Class : 16
Server : (machine name)
Message : Could not create constraint. See previous errors.
Procedure :
LineNumber : 1
Exception calling "ExecuteNonQuery" with "1" argument(s): "ExecuteNonQuery failed for Database 'UT_Config
'. "
At C:\Users\(username)\Documents\Install\DatabaseInstallerFunctions.ps1:1885 char:40
+ $db.ExecuteNonQuery <<<< ($filedata)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
任何帮助或想法都将不胜感激。
答案1
错误消息表明存在外键违规。您的代码删除了触发器,但保留了外键约束