foreign-keys

Multiple foreign keys?

天大地大妈咪最大 提交于 2019-12-03 15:57:45
问题 I've got a table that is supposed to track days and costs for shipping product from one vendor to another. We (brilliantly :p) stored both the shipping vendors (FedEx, UPS) with the product handling vendors (Think... Dunder Mifflin) in a "VENDOR" table. So, I have three columns in my SHIPPING_DETAILS table that all reference VENDOR.no. For some reason MySQL isn't letting me define all three as foreign keys. Any ideas? CREATE TABLE SHIPPING_GRID( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY

Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed

断了今生、忘了曾经 提交于 2019-12-03 15:51:04
I'm working on adding Django 2.0 support to the django-pagetree library. During automated testing, using an sqlite in-memory database, I'm getting a bunch of errors like this: File "/home/nnyby/src/django-pagetree/pagetree/tests/test_models.py", line 638, in setUp 'children': [], File "/home/nnyby/src/django-pagetree/pagetree/models.py", line 586, in add_child_section_from_dict ... File "/home/nnyby/src/django-pagetree/venv/lib/python3.5/site-packages/django/db/backends/base/base.py", line 239, in _commit return self.connection.commit() django.db.utils.IntegrityError: FOREIGN KEY constraint

MySQL: Creating table with FK error (errno 150)

…衆ロ難τιáo~ 提交于 2019-12-03 15:16:18
问题 I've created a model with MySQL Workbench and am now attempting to install it to a mysql server. Using File > Export > Forward Engineer SQL CREATE Script... it outputs a nice big file for me, with all the settings I ask for. I switch over to MySQL GUI Tools (the Query Browser specifically) and load up this script (note that I'm going form one official MySQL tool to another). However, when I try to actually execute this file, I get the same error over and over SQLSTATE[HY000]: General error:

Understanding Relationships & Foreign Keys in Mongoose

巧了我就是萌 提交于 2019-12-03 15:14:53
问题 In MongoDB/Mongoose, how do I define a relationship? I think there are a few ways I've seen, but I'm not sure I understand the differences or when do I use which. I am using Mongoose 3 I've defined Todo and TodoList model, where the relationship is obvious. So following the docs http://mongoosejs.com/docs/documents.html, I've defined classes like: # Todo.coffee mongoose = require "mongoose" todoSchema = mongoose.Schema name: String desc: String dueOn: Date completedOn: Date module.exports =

Create Foreign Key using Data Annotations

自闭症网瘾萝莉.ら 提交于 2019-12-03 14:46:16
In the code below, I need to set a foreign key constrant on ParentInfoAddProperties.ParentQuestionAnswersId so that it is dependent on ParentQuestionAnswers.Id (which is a Primary Key). I am attempting to do so using data annotations but Entity Framework 6 wants to create a new Foreign Key column in my ParentQuestionAnswers table which references the ParentInfoAddProperties.Id column not the ParentInfoAddProperties.ParentQuestionAnswersId column. I do not want Entity Framework to create a new foreign key column. I'd greatly appreciate if someone can explain what data annotations or (if

How to ensure data integrity when using Table Per Subclass?

☆樱花仙子☆ 提交于 2019-12-03 14:45:14
I am using the table per subclass strategy in Grails by setting the tablePerHierarchy property of the static mapping field in my superclass to false. This way, Grails creates one table for my superclass and one additional table for each of my subclasses. However, while the superclass and subclass records share the same ID (primary key), there are no foreign key constraints to keep them consistent, i.e. it is possible to delete the superclass record, leaving the subclass record in an invalid state. I want to know if there is a setting/property to make GORM address this in some way, e.g. through

multicolumn primary keys in rails

孤街醉人 提交于 2019-12-03 14:38:34
I'm trying to migrate a desktop application to rails (also dealing with quite old fashioned existing database). The problem is that I don't have a unique ID in one column, but it's three columns of a table that guarantee uniqueness of a record. Given I have three tables: authors author_name, author_letter, author_nr1, author_nr2 ... titles titel_nr, titel_name, ... author_titles titel_nr, author_letter, author_nr1, author_nr2 The "primary key" of authors consists of author_letter, author_nr1, author_nr2 here. So do I need sort of a multicolumn primary key here to have rails associations

Postgresql constraint

懵懂的女人 提交于 2019-12-03 14:23:01
问题 I cannot seem to get this right, I am trying to modify a field to be a foreign key, with cascading delete... what am i doing wrong? ALTER TABLE my_table ADD CONSTRAINT $4 FOREIGN KEY my_field REFERENCES my_foreign_table ON DELETE CASCADE; 回答1: It would help if you posted the error message. But I think you are just missing the parenthesis: ALTER TABLE my_table ADD CONSTRAINT my_fk FOREIGN KEY (my_field) REFERENCES my_foreign_table ON DELETE CASCADE; 回答2: Just guessing: shouldn't you add a

How to use an auto incremented primary key as a foreign key as well?

两盒软妹~` 提交于 2019-12-03 14:18:49
This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; CREATE TABLE `child` ( `parent_id` int(11) DEFAULT NULL, `related_ids` int(11) DEFAULT NULL, KEY `parent_id` (`parent_id`), KEY `related_ids` (`related_ids`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; And then a constraint: ALTER TABLE `parent` ADD FOREIGN KEY (`id`) REFERENCES `child` (`parent_id`); As you can see the table parent has an auto-incremented primary key "id", which is also being used as a

Get all employee who directly or indirectly reports to an employee, with hierarchy level no

故事扮演 提交于 2019-12-03 13:48:54
问题 I have a Employee table like emp_id bigint, reports_to bigint, emp_name varchar(20), Constraint [PK_Emp] Primary key (emp_id), Constraint [FK_Emp] Foreign key (reports_to) references [MSS].[dbo].[Emp]([emp_id]) emp_id reports_to emp_name ------ ------ -------------- 1 null Sumanta 2 1 Arpita 3 null Pradip 4 1 Sujon 5 2 Arpan 6 5 Jayanti I want to get all the employees that directly or indirectly reports to Sumanta or emp_id(1), and with hierarchy level, like this: emp_id hierarchy_level emp