foreign-keys

Django model with 2 foreign keys from the same table

I wanted a Django model with 2 foreign keys from the same table. It's an event table which has 2 columns for employees: the 'actor' and the 'receiver'. But I get this error: Error: One or more models did not validate: tasks.task: Intermediary model TaskEvent has more than one foreign key to Employee, which is ambiguous and is not permi...

Can a foreign key reference a non-unique index?

I thought a foreign key meant that a single row must reference a single row, but I'm looking at some tables where this is definitely not the case. Table1 has column1 with a foreign key constraint on column2 in table2, BUT there are many records in table2 with the same value in column2. There's also non-unique index on column2. What does ...

Should I use foreign keys?

Duplicate of What’s wrong with foreign keys? I use MS Sql Server with a large database about 4 GB data. I search around the web why I should use foreign keys. by now I only indexed the keys used to join tables. Performance is all fine, dataintegrety is no problem. Should I use foreign keys? Will I get even more performance with fo...

Entity Framework: Conditional foreign key

Hi all, I have the following schema in the database: BillingReferences (ReferencingType tinyint, ReferencingId tinyint, ReferencedType tinyint, ReferencedId tinyint, IsActive bit) - where all fields (except IsActive) are part of a Unique Index. BillingType (BillingTypeId tinyint, Name varchar(50)) ReferencingType and ReferencedType i...

Implementing foreign key type relationships in XSD schema

I'm trying to wrap my head around xml schemas and one thing I'm trying to figure out is how to do relational type schemas where on element refers to another, possibly in another schema altogether. I've looked at the xsd:key and xsd:keyref and it seems like the sort of thing I'm interested in, but I'm not sure. Initially I just set attrib...

Linq To SQL Without Explicit Foreign Key Relationships

I am working with a few legacy tables that have relationships, but those relationships haven't been explicitly set as primary/foreign keys. I created a .dbml file using "Linq To Sql Classes" and established the proper Case.CaseID = CaseInfo.CaseID association. My resulting class is CasesDataContext. My Tables (One to many): Case ---...

Rails model with foreign_key and link table

I am trying to create a model for a ruby on rails project that builds relationships between different words. Think of it as a dictionary where the "Links" between two words shows that they can be used synonymously. My DB looks something like this: Words ---- id Links ----- id word1_id word2_id How do I create a relationship between t...

How do you add Foreign Key Relationships?

I'm working with an existing SQL 2005 database that was not implemented with FK relationships between tables. I tried to add the relationships with a database diagram and my application immediately blew up trying to edit or insert any data that is tied to the new FK. dbo.person [person_id | firstname | lastname | dateofbirth] dbo.campa...

What exactly is a foreign key?

Ok. So I know what a primary key in DB is. If you have a table in a database, a primary key is a single value that is unique to each row in your table. For example: id | name | whatever ------------------------- 1 Alice .... 2 Bob .... 45 Eve .... 988 .... .... So I need a good, simple examp...

Foreign key refering to primary keys across multiple tables?

Hi! I have to two tables namely employees_ce and employees_sn under the database employees. They both have their respective unique primary key columns. I have another table called deductions, whose foreign key column I want to reference to primary keys of employees_ce as well as employees_sn. Is this possible? for example employee...

how do I add a foreign key pointing to the same table using myphpadmin?

I have an existing InnoDB table which already has foreign keys pointing to different tables. But when I try to create a foreign key pointing to the Primary index, I get an error (check data type). The table is User with User_Id as the Primary. I want a foreign key Manager_ID which is a FK to User_Id. Both of INT Both of Length 10 Uns...

Foreign Key Issues in Rails

Took me a while to track down this error but I finally found out why. I am modeling a card game using the Rails framework. Currently my database looks (mostly) like this: cards cards_games games ----- ----------- ----- id id id c_type card_id ... value game_id other_stuff ...

How to retrieve objects with a foreign key self

I have a model Category which has a FK reference to itself. How can i send the data to a template and make it look like this Category 1 List item List item Category 2 List item List item ...

Entity framework and foreign keys

Hi, I have two tables a car tables which contains different properties for a car, and a carmodeldefinition which is a foreign key to a table with the same name. The cardefinition table contains the different cars and models. I have mapped them in the entity framework http://img21.imageshack.us/my.php?image=entityframeworkfk.jpg (can't g...

Comments table with multiple types of parents

My site (ASP.NET/C#/MS-SQL 2005) has multiple sections that allow for comments (User profiles, image pages, videos, etc). I want to store everything in a single comments table. My issue is linking the comment back to its parent. The user profiles' primary keys are uniqueidentifiers, while the images and videos use ints. I'd like to ha...

JPA @OneToMany Sets and unique contstaints

I have the following scenario: I have a system full of users. There is a desire to run contests for users who log into the site over a week or so. Therefore I needed to create a new Contest object which would contain both the entries and the winners. I created something like this: private Set<User>; @OneToMany(cascade = CascadeType....

How to get all tables that have FKs to another table?

Is there any way to get all tables that have foreign keys to another table in oracle with a query? ...

Manipulating Data in Django's Admin Panel on Save

Ok, so here's the skinny: # models.py class Article( models.Model ): title = models.CharField( max_length = 255 ) author = models.ForeignKey( User ) published_at = models.DateTimeField( auto_now_add = True ) body = models.TextField( ) def __unicode__( self ): return self.titl...

MySQL: How do I find out which tables reference a specific table?

I want to drop a table but it is referenced by one or more other tables. How can I find out which tables are referencing this table without having to look at each of the tables in the database one by one? ...

Basics of Foreign Keys in MySQL?

Is there any good explanation of how to use MySQL's foreign key construct? I don't quite get it from the MySQL docs themselves. Up until now I've been handling things like foreign keys with joins and programming code. And the second part of the question, are there any improvements to be made by using MySQL's inbuilt foreign keys? ...