foreign-keys

LINQ to SQL Foreign Key Constraint conflicts

I'm having a problem with LINQ. I have 2 tables (Parent-child relation) Table1: Events (EventID, Description) Table2: Groups (GroupID, EventID(FK), Description) Now i want to create an Event an and a child. Event e = new Event(); e.Description = "test"; Datacontext.Events.InsertOnSubmit(event) Group g = new Group(); g.Description =...

Maximum Length for a foreign key in DB2? (SQL0107N)

We have two installations of DB2. When defining a foreign key with a long name, it works fine on one instance, but not on the other (we get a SQL0107N Name too long - max length is 18). What is causing this different behaviour? Is there a parameter we can change or is it version dependant? ...

Error 1005 when adding a foreign key constraint on mysql table

Hello, I have a problem when upgrading a django and mysql app with south. I've tried to make a sql-based upgrade with the code generated by the django sqlall command and I have a similar problem. Here is the sql code: CREATE TABLE `programmations_basissupport` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `value` numer...

SQL Server Delete - Froregin Key

I have got two tables in Sql Server 2005: USER Table: information about user and so on. COUNTRY Table : Holds list of whole countries on the world. USER_COUNTRY Table: Which matches, which user has visited which county. It holds, UserID and CountryID. For example, USER_COUNTRY table looks like this: ID -- UserID -- CountryID 1 -- 1 ...

Mutiple FK columns all pointing to the same parent table - a good idea?

For those of you who live and breath database design, have you ever found compelling reasons to have multiple FK's in a table that all point to the same parent table? We recently had to deal with a situation where we had a table that contained six columns which were all FK columns to the same parent table. We're debating whether this in...

MySQL primary/foreign key size?

I seem to see a lot of people arbitrarily assigning large sizes to primary/foreign key fields in their MySQL schemas, such as INT(11) and even BIGINT(20) as WordPress uses. Now correct me if I'm wrong, but even an INT(4) would support (unsigned) values up to over 4 billion. Change it to INT(5) and you allow for values up to a quadrillio...

Can't save form content to database

I'm trying to save 100 characters form user in a 'microblog' minimal application. My code seems to not have any mystakes, but doesn't work. The mistake is in views.py, I can't save the foreign key to user table. models.py looks like this: class NewManager(models.Manager): def create_post(self, post, username): new = self.model(po...

Django save, column specified twice

Hey, I would like to save a modified model, but I get Programming error - that a field is specified twice. class ProductInfo(models.Model): product_info_id = models.AutoField(primary_key=True) language_id = models.IntegerField() product_id = models.IntegerField() description = models.TextField(blank=True) status = m...

Django: Set foreign key using integer?

Is there a way to set foreign key relationship using the integer id of a model? This would be for optimization purposes. For example, suppose I have an Employee model: class Employee(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) type = models.ForeignKey('EmployeeType') ...

Subsonic 3 foreign key (relationship) keep changing the appended number

Hi all, I have couple foreign key relationships in my tables, where multiple keys reference to the same primary from a different table. Whenever I try to run the "Run Custom Tool" when I make changes/add/delete new table, from time to time, the generated class append a different number. For example, at the moment, I have this generated ...

circular foreign key. How do i handle them?

Much of my sql code is generated (from POD). Now i have issue where table user_data has a FK to ref_status which points back to two different user_data. My code does the following begins a transaction looks at user_data (and adds it to a list) sees ref_status then repeats #2 with it executes the create table ref_status code Then i g...

When to use a foreign key in MySQL

Is there official guidance or a threshold to indicate when it is best practice to use a foreign key in a MySQL database? Suppose you created a table for movies. One way to do it is to integrate the producer and director data into the same table. (movieID, movieName, directorName, producerName). However, suppose most directors and produ...

oracle primary_key and foreign_key

Is it possible to maintain relationship between two tables without primary key and foreign key if it is possible then how? ...

How to handle Foreign Keys with Entity Framework

I have two entities. Groups. Pools. A Group can create many pools. So I setup my Pool table to have a GroupID foreign key. My code: using (entity _db = new entity()) { Pool p = new Pool(); p.Name = "test"; p.Group.ID = "5"; _db.AddToPool(p); } This doesn't work. I get a null reference exception on p.Group...

How to enforce foreign keys using Xerial SQLite JDBC?

According to their release notes, the Xerial SQLite JDBC driver supports foreign keys since version 3.6.20.1. I have tried some time now to get a foreign key constraint to be enforced, but to no avail. Here is what I came up with: public static void main(String[] args) throws ClassNotFoundException, SQLException { Class.forName("...

Cannot add or update a child row: a foreign key constraint fails

// Getting the id of the restaurant to which we are uploading the pictures $restaurant_id = intval($_GET['restaurant-id']); if(isset($_POST['submit'])) { $tmp_files = $_FILES['rest_pics']['tmp_name']; $target_files = $_FILES['rest_pics']['name']; $tmp_target = array_combine($tmp_files, $target_files); $upload_dir = $rest...

django forms from two tables referencial integrity

i have a class named cv,and a class named university, and each user that completes his cv, should choose a University he studyes at. My problem is: one student can study at one or 2 or three universities, or may be a user that is not student. I need to take this data into a form, and i use ModelForm. The data from the Cv class, and fr...

c# linq to sql join problem

i am trying to do using (UserManagementDataContext context = new UserManagementDataContext()) { var users = from u in context.Users where u.UserEMailAdresses.EMailAddress == "[email protected]" select u; return users.Count(); ...

Fluent composite foreign key mapping

Hi, I wonder if this is possible to map the following with fluent nhibernate: A document table and a document_revision table will be the target tables. The document_revision table should have a composite unique key consisting of the document_id and the revision number (where the document_id is also the foreign key to the document tabl...

can we have a foreign key which is not a primary key in any other table?

it is written in every book that foreign keys are actually primary key in some other table but can we have a foreign key which is not primary key in any other table ...