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.

link|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
feedback

1 Answer

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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