Toad World® Forums

Can not drop a table referenced by foreign key constraint

Hello: I have a database that has (among others) a table that has 2 child tables. I made a change in one of the child tables. I created and ran an alter script from TDM. The script fails with the following messages: “Could not drop object ‘dbo.rubricResult’ because it is referenced by a FOREIGN KEY constraint …”. Then later on I get the message: “There is already an object named ‘PK_rubricScore’ in the database. … Could not create constraint. See previous errors …”. RubricScore is the child and RubricResult is the parent.

The alter script is trying to drop the parent before it drops the child. I have been doing the same exact type of change at least every few weeks for some years. Since the last time I did an update, I have not changed any settings. (I create the alter script by comparing my model to a reverse engineered live database). The sql server has not changed etc. I am now very confused and do not know how to proceed. Why have I never had this problem before? I have not recently upgraded TDM. I assume there must be some setting somewhere that forces children to be dropped before trying to drop parents? Any suggestions?

In my case we have many clients with identical databases and I run the same alter script against all client databases, so making this one change manually in SQL is not a real option. I am using TDM 5.2.4.27 and MS SQL 2005

I have just figured it out. Stupid mistake.

Every table in TDM has a caption and a name (and in my database these are always identical to each other). Somehow in the rubricScore table I had the caption set to rubricScore and the name set to “otObserved” - no idea how I did that. However, now that that is fixed - everything is back to normal and I have just successfully run an alter script against a live database.