Linked Questions
21 questions linked to/from Can table columns with a Foreign Key be NULL?
0 votes
1 answer
95 views
Why the FOREIGN KEY doesn't work for the LOOP? [duplicate]
I've created two tables: 1.Table CREATE TABLE IF NOT EXISTS us_tAddress ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, country VARCHAR(100), city VARCHAR(100), zip VARCHAR(100), street ...
473 votes
11 answers
683k views
Can a foreign key be NULL and/or duplicate?
Please clarify two things for me: Can a Foreign key be NULL? Can a Foreign key be duplicate? As fair as I know, NULL shouldn't be used in foreign keys, but in some application of mine I'm able to ...
26 votes
6 answers
47k views
SQL column default value with Entity Framework
I am trying to use Code-First EF6 with default SQL values. For example, I have a "CreatedDate" column/property not null with a default in SQL of "getdate()" How do I represent this in my code Model?...
7 votes
5 answers
2k views
Oracle - Partially nullable composite foreign key
I have a legacy Oracle database that has a strange quirk I wanted to make sense of. It has a composite foreign key where some columns are nullable. To me this smells like a bad design by a careless ...
4 votes
2 answers
8k views
Make Foreign Key (string field) nullable
My model is like this public class Appointment { public int AppointmentID { get; set; } public string AppointmentCode { get; set; } public string ApplicationUserId { get; set; } [...
4 votes
1 answer
3k views
Creation of foreign key fails on existing table, but no orphan records found
Using Firebird 2.1. While refactoring a large system I want to create a foreign key between tables that both are already populated: ALTER TABLE CMS_ARTRANS ADD CONSTRAINT FK_ARTRANS_PRACTITIONER_ID ...
2 votes
3 answers
7k views
How to make foreign key as NULLABLE in SQL?
CREATE TABLE [M].[SocialInfo] ( [Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY DEFAULT newid(), [MemberId] UNIQUEIDENTIFIER DEFAULT newid(), [GroupId] UNIQUEIDENTIFIER DEFAULT newid(), ...
2 votes
2 answers
4k views
"The INSERT statement conflicted with the FOREIGN KEY constraint" when insert is NULL
I have this problem: I have this table which has 5 columns: ID, Usuario_IdUsuario, Artista_IdArtista, Disco_IdDisco, Lista_IdLista. The last 4 are foreign keys, and the last 2 allow nulls, because at ...
0 votes
1 answer
3k views
CakePHP Auth with two tables (models)
I have two tables in my database, one for admins (named Admins) and the other one for normal users, named : utilisateurs (in french). I know i have to use cakePHP's convention which says i must create ...
0 votes
2 answers
2k views
Mysql Cannot add or update a child row a foreign key constraint fails ON DELETE NO ACTION ON UPDATE NO ACTION
I have 'parent' and 'child' tables. There is a column 'parent_id' in 'child' table and it is a foreign key. 'id' column in 'parent' table is NOT NULL and INT. 'parent_id' is also INT but DEFAULT NULL. ...
0 votes
2 answers
1k views
MySql Update and Set null to field with foreign key to other table
I have tables like this: Notes ID | NAME | CATEGORY 1 | test | 1 2 | test2| 2 Notes Category ID | NAME | COUNT 1 | tCat | 1 2 | tCat2| 1 And I have foreign key CATEGORY <-> Notes Category....
2 votes
2 answers
907 views
Why can't I -- or how do I -- insert NULL values into my MySQL database using the WordPress API
I've been working on this for hours and can't figure out how to insert/update NULL values for columns. For example, I have a block of code case 'add': { $message = $wpdb->insert('...
0 votes
1 answer
618 views
Unique index with one nullable key and foreign key
We have the following table and we ran into an issue that our unique key is not working (as expected). CREATE TABLE `documentation_photos` ( `commissionID` smallint(5) unsigned NOT NULL, `periodID`...
0 votes
1 answer
339 views
Can a Column be Nullable, Unsigned and a foreign key?
I have several tables which I want to reference to a particular table tools. I have multiple foreign keys assigned to this table. Some times, these foreign keys may not have values but sometimes they ...
0 votes
2 answers
171 views
mariadb foriegn key insert error
So, I was using mysql server on Centos 6 and it was alright then, I shifted my code to Centos 7 server. I had a constraint in an table where I used to insert null values by default in MySQL Server. I ...