Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to install Databases on a new windows 7 machine with powershell code that was meant for windows xp. I have been able to fix most of the problems as I have come across them but I have been stuck at this particular problem for several hours.

I am trying to update table keys;

# 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)
    }

I am getting the following error.

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

Any help or ideas would be appreciated.

share|improve this question
    
My coworker was able to do this on SQL Server Dev Edition (64 bit) (version 10.0.1600.22). I have the same thing but R2 (version 10.50.1600). Could that make a difference? –  k_Dank Aug 10 '11 at 18:22

1 Answer 1

The error message indicates a foreign key violation. You're code is dropping triggers, but leaving foreign key constraints

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.