foreign-keys

Several similar DDL with different result in foreign key

This is a further discussion on this question: http://stackoverflow.com/questions/2321270/why-is-it-still-possible-to-insert-a-foreign-key-that-doesnt-exist This works: CREATE TABLE products ( id integer unsigned auto_increment primary key ) ENGINE=INNODB; CREATE TABLE orders ( id integer PRIMARY KEY auto_increment, pr...

Using Entity Framework how do I filter by a foreign key using multiple enumeration values?

Two tables (MainTable and EventType). EventType is represented in code as an enumeration and is foreign keyed in the database so that it looks like; Public enum EventTypeId As Integer Blah = 1 Blurgh = 2 Whoo = 3 End Enum I can run the following query fine; From M in dbx.MainTable Where M.EventType.EventTypeId = 1 But I...

Foreign Key doesn't stop me entering data MySQL

I have a table which has one column as a foreign key joining to another table. It's a cricket question where I have a table called Fixtures and another called Inning. Inning table has a FixtureId column relates to the Fixture table. I would expect that If i do a insert on the inning table using a FixtureId that doesn't relate to a F...

Reasons why you wouldn't use a foreign key? [php + MySQL]

I'm working on an old web application my company uses to create surveys. I looked at the database schema through the mysql command prompt and thought the tables looked pretty solid. Though I'm not a DB guru I'm well versed in the theory behind it (having taken a few database design courses in my software engineering program). That being...

SQL Server: How to ignore referential integrity until COMMIT?

i have a process to move rows from one database to another. Because of some circular foreign key reference chains i cannot remove the rows from the old database, nor can i insert them into the new database. Since the entire operation happens in a transaction1, i want SQL Server to ignore referential integrity failures until i call COMMI...

Save or update for FK relationship Sqlalchemy

I've googled, but haven't been able to find the answer to this seemingly simple question. I have two relations, a customer and an order. Each order is associated to a single cusomter, and therefore has a FK relationship to the customer table. The customer relation only stores customer names, and I have set a unique constraint on the cus...

How to delete a record when two tables have foreign key referenced to each other?

Delete any record of them will report an error like this: ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails How to overcome this problem? ...

Display value in Charfield for foreign key in django on error

Let's say I've got a model and it has a foreign key to another one. class ModelA(models.Model): field = models.CharField(max_length=100) class ModelB(models.Model): model_a = models.ForeignKey(ModelA) Than I've got this form: class FormB(models.ModelForm): model_a = forms.CharField(required=True) def clean(self): ...

How do I create a Foreign Key?

Hi I am working on my assignment. It has 8 tables. Each table has a primary key. What do i do to generate a foreign key to a table? My reason for asking is that when I generate a primary key, a key symbol appears on the left. What do i do to make something a foreign key? ...

Is a simple MySql Database possible?

Steps: I want a registered user to be able to insert values into a table. Those values would only be able to be seen or edited by the user. (a few rows) I have a registration/login page and insert form page complete and they can add do their respective jobs. Here's the problem and i realize it probably a super simple answer: How d...

Mysql foreign key by non unique key -- how is that possible?

I was migrating mysql database to postgres and stumbled across the following block in DDL (Note: This is what I got from mysqldump): CREATE TABLE `catalog_property_value` ( `id` int(10) unsigned NOT NULL, `property_id` int(10) unsigned NOT NULL, `sort` int(10) unsigned NOT NULL, `value_number` decimal(15,5) DEFAULT NULL, `valu...

Can table columns with a foreign key be null?

For example, I have a table which has several ID columns to other tables. I want a foreign key to force integrity only if I do put data in there. If I do an update at a later time to populate that column then it will still check the constraint (this is likely database server dependant, i'm using MySQL & InnoDB table type). I believe this...

Composite Primary keys and Foreign key constraint error

Hi, I have an SQL table defined as below: CREATE TABLE [TestComposite] ( ID int, SiteUrl nvarchar(255), Name nvarchar(max) NOT NULL, ParentID int NULL, PRIMARY KEY (ID, SiteUrl) ); Items and folders are stored inside the same table, if an item is inside a folder, the ParentID column is the ID of the ...

constraint Problem /Solution in sqlServer

Hi Sorry for my shallow question . Imagine I have 4 Tables in my DataBase (SQLServer 2005). Picture , News , product and gallery Tables . At my Picture Table i Have 3 foreign key to all 3 other tables , And all foreign keys are nullable and default value = -1 . All tables have Primary keys and is Identity . At my webform every ph...

which cakephp relationship should be used for groups of users? can haveMany use array for foreign_ID?

In my tennis application, my 'match' table has two players (obviously). I've used player1_id and player2_id as a way to track the user ids. I haven't included a user_id foreign key though. There is also a 'user' table where I want to pull player's names from. Because 'match' has more than one user and users have more than one model, ...

Can't grab foreign key during after_create callback because it doesn't exist yet!

I have some models all linked together in memory (parent:child:child:child) and saved at the same time by saving the top-most parent. This works fine. I'd like to tap into the after_create callback of one of the children to populate a changelog table. One of the attributes I need to copy/push into the changelog table is the child's f...

nhibernate mapping does not save/insert keys of inserted subclasses

After having changed around my mappings a bit ( see my other question about cascade-delete for reasons) , i tried inserting a completely new object and all its subclasses. After this another problem emerged, an issue with the insertion of the keys into the database. Situation is as follows: I have an object with 2 tiers of subclasses, ...

Entity Framework Update existing foreign Key reference to another

Hi, I have two tables Team_DATA and Driver_PROFILE_DATA in an SQL database. For every driver_profile there can be many teams. So there's a one-to-many relation on the driver_profile to team_data table. I want to update a team_data foreign key reference in the Driver_profile table of an already existing record to another team_data rec...

MySQL Composite Foreign Key Insert Failing

I have 2 tables with a composite foreign key between the 2. When I try to insert a row into the child table, I get a restraint failure, even though the values exist in the parent table. Here's a overview of the parent table: CREATE TABLE `residual_reports` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `processor` enum('1','2','3...

How do you add a NOT NULL FOREIGN KEY column to an existing (populated) table in MS SQL?

I need to add a NOT NULL column to an existing (populated) table that will be a foreign key to another table. This brings about two problems: When you add the column, its value cannot be null - using a default is not an option (unless it is removed later on) because the database logic is used in the server side validation when a user e...