foreign-keys Questions

4

Solved

So as the title says, how can I know if a field of a Model is a foreign key in Laravel ? Supose I have a FK column called show_type_id and a model named Event and I want to know if there is a funct...
Cappella asked 1/10, 2020 at 10:45

1

Is it possible to create a partial foreign key (similar to partial indexes) in general sql / postgresql? I have not found a way to force referential integrity in the following case: Table A is soft...
Helsell asked 28/11, 2017 at 13:1

5

Solved

How can I set the name of a foreign key in php laravel? Schema::table('TABLE_NAME', function (Blueprint $table) { $table->foreign(XXX) ->references(XXX) ->on('REF_TABLE') ->onDelete...
Cap asked 22/3, 2021 at 11:16

4

Solved

I get the following error when I try to run an insert into one of my tables. Cannot assign "1": "Team.department_id" must be a "Department" instance Admittedly I'm s...
Arkose asked 15/6, 2016 at 15:36

5

Solved

I am using the Django REST Framework 2.0. Here is my model class: class Mission(models.Model): assigned_to = models.ForeignKey('auth.User', related_name='missions_assigned', blank = True) Here ...
Purgation asked 16/5, 2013 at 13:40

2

Solved

I'm translating an old database SyBase to MySQL and I have this DDL Query: ALTER TABLE "DBA"."tab_prodotto" ADD FOREIGN KEY "fkey_idlinea" ("tpr_idlin") REFERENCES "DBA"."linea" ("lin_id") go C...
Jacintha asked 13/6, 2012 at 13:36

11

The logic is of the model is: A Building has many Rooms A Room may be inside another Room (a closet, for instance--ForeignKey on 'self') A Room can only be inside another Room in the same build...
Massengale asked 1/12, 2009 at 6:1

4

Solved

Is this correct? class Customer(models.Model): account = models.ForeignKey(Account) class Order(models.Model): account = models.ForeignKey(Account) customer = models.ForeignKey(Customer, limi...
Gainful asked 28/12, 2009 at 8:56

8

I'm on a MySQL database. I'm doing this, but it doesn't work. ALTER TABLE `object` DROP FOREIGN KEY IF EXISTS `object_ibfk_1`; I've tried to put this IF EXISTS wherever I could. How can check i...
Aleppo asked 18/6, 2013 at 5:56

16

Solved

Why doesn't a TRUNCATE on mygroup work? Even though I have ON DELETE CASCADE SET I get: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, CONST...
Prohibitionist asked 27/3, 2011 at 21:57

17

Solved

I want to add a Foreign Key to a table called "katalog". ALTER TABLE katalog ADD CONSTRAINT `fk_katalog_sprache` FOREIGN KEY (`Sprache`) REFERENCES `Sprache` (`ID`) ON DELETE SET NULL ON UPDATE ...
Dilworth asked 5/4, 2012 at 12:2

32

Solved

Using MSSQL2005, can I truncate a table with a foreign key constraint if I first truncate the child table (the table with the primary key of the FK relationship)? I know that I can either Use a ...
Health asked 31/10, 2008 at 15:6

7

Solved

I would like to delete rows which contain a foreign key, but when I try something like this: DELETE FROM osoby WHERE id_osoby='1' I get this statement: ERROR: update or delete on table "osoby...
Varico asked 6/1, 2013 at 12:27

12

Solved

I have a table whose primary key is used in several other tables and has several foreign keys to other tables. CREATE TABLE location ( locationID INT NOT NULL AUTO_INCREMENT PRIMARY KEY ... ) E...
Hermit asked 8/5, 2009 at 5:25

8

Solved

In SQL Server 2008 and given TableA(A_ID, A_Data) TableB(B_ID, B_Data) ViewC(A_or_B_ID, A_or_B_Data) is it possible to define TableZ(A_or_B_ID, Z_Data) such that Z.A_or_B_ID column is constraine...
Etty asked 15/1, 2009 at 15:17

20

Solved

I've been wrestling with this for a while and can't quite figure out what's happening. I have a Card entity which contains Sides (usually 2) - and both Cards and Sides have a Stage. I'm using EF Co...

14

I'm trying to modify a M2M field to a ForeignKey field. The command validate shows me no issues and when I run syncdb : ValueError: Cannot alter field xxx into yyy they are not compatible types (yo...
Carabineer asked 14/11, 2014 at 10:20

14

Solved

I need to make some changes to a SQL Server 2008 database. This requires the creation of a new table, and inserting a foreign key in the new table that references the Primary key of an already ex...
Dislocate asked 12/1, 2011 at 10:41

6

Solved

I have a large database with over 150 tables that I've recently been handed. I'm just wondering if there is an easy way to view all foreign key constraints for the entire DB instead of on a per-tab...
Taler asked 21/4, 2010 at 15:53

26

Why does add a foreign key to the tblDomare table result in this error? The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK__tblDomare__PersN__5F7E2DAC". The conflic...
Fruitless asked 17/2, 2014 at 21:9

3

Solved

I have 2 tables, User and Employee. Each user is given a User_ID and that is a primary key in the User table and a foreign key in the Employee table. Can that attribute in the Employee table also b...
Refresh asked 11/2, 2012 at 22:2

10

What is the best way to set a default value for a foreign key field in a model? Suppose I have two models, Student and Exam with student having exam_taken as foreign key. How would I ideally set a ...
Boilermaker asked 16/2, 2012 at 13:20

5

Using Django 1.8 on Python 3.4.1 with models: class Product(models.Model): name = models.CharField(max_length=255) # some more fields here def __str__(self): return self.name class PricedPr...
Instruction asked 15/4, 2015 at 10:8

5

Solved

My models.py class Order(models.Model): user = models.ForeignKey(User, blank=True, null=True, on_delete=models.PROTECT) customer_email = models.EmailField(blank=True, null=True, default=None) c...
Gifted asked 12/2, 2019 at 17:39

21

I'm having some problems creating a foreign key to an existing table in a MySQL database. I have the table exp: +-------------+------------------+------+-----+---------+-------+ | Field | Type | Nu...
Ramble asked 3/2, 2014 at 11:22

© 2022 - 2024 — McMap. All rights reserved.