No Foreign Keys / Constraint Error - FogBugz Knowledge Exchange most recent 30 from http://fogbugz.stackexchange.com 2013-05-19T07:03:59Z http://fogbugz.stackexchange.com/feeds/question/5477 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://fogbugz.stackexchange.com/questions/5477/no-foreign-keys-constraint-error No Foreign Keys / Constraint Error Andrew 2010-10-21T15:26:37Z 2010-10-22T20:05:33Z <p>Hi,</p> <p>I've been evaluating FogBugz 8 online for a little while and so far I've been impressed. Today I decided to use the "Download Database" feature (which is a pretty nice feature). I grabbed the SQL Sever version and loaded it up to see what was inside.</p> <p>My first stop with a new database is usually the database diagram node. If there are any diagrams it really helps (me) with quickly understanding a database. Since this was basically a backup of a production database I wasn't really surprised that there were none in there, so I decided to build my own using the <a href="http://fogbugz.stackexchange.com/fogbugz-database-schema" rel="nofollow">online schema documentation</a>.</p> <p>I added the project table and all related tables (based on the schema documentation). I was surprised to find that there were no foreign keys actually defined in the database. I proceeded to add them myself and found a couple odd things:</p> <ol> <li><p>The TokenAssociation table has the ixProject field set to smallint instead of int like its parent (project) table. So until I altered this I was unable to define the relationship.</p></li> <li><p>I tried to define a relationship between the Project and ACL tables, but the constraint failed because there was a row in the ACL table with a ixProject ID value that did not exist in the project table (value was zero)</p></li> </ol> <p>These are both problems that would not be present if official constraints had been defined. The first one seems a little odd to me, and should probably be fixed? The second could be a design decision for maintaining history or something. I don't know.</p> <p>Honestly, I'm a little leery of databases with no relationships defined because it's so easy to introduce errors like I've outlined above. Is this so you can support both MySQL and SQL Server maybe? Is it for performance considerations? I'm curious (obviously).</p> <p>Oh, also, I was going to submit this as a bug report, but I couldn't find where to do that...is this basically the correct place for this?</p> <p>Thanks, Andrew</p> http://fogbugz.stackexchange.com/questions/5477/no-foreign-keys-constraint-error/5478#5478 Answer by Ted for No Foreign Keys / Constraint Error Ted 2010-10-21T15:36:34Z 2010-10-22T20:05:33Z <p>FogBugz does not enforce or use foreign key constraints. For the most part, FogBugz tries to deal with these things in code so there's one place to go when things aren't working right.</p> <p>I'd say the most likely consequence of adding constraints to your database will be to cause FogBugz to fail at some point. We realize that this makes the database harder to diagram, but we have strong (column) naming conventions to make up for it. (Apologies for the inconsistent pluralization of table names... sigh.)</p>