foreign-keys

MySQL attempting to delete all rows which are not constrained by foreign key

廉价感情. 提交于 2019-12-05 18:07:24
Okay, this is (probably) a very simple question, but I am afraid I know almost no MySQL, so please put up with me. I'm just trying to delete every row from one table which is not constrained by a Foreign Key in another table - a specific table, there are only two tables involved here. The create statements look a bit like: CREATE TABLE `testschema`.`job` ( `Job_Id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Comment` varchar(255) DEFAULT NULL, PRIMARY KEY (`Job_Id`) USING BTREE, ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE `ermieimporttest`.`jobassignment` (

How to define a one to one self reference using Entity Framework Code First

时光总嘲笑我的痴心妄想 提交于 2019-12-05 18:06:18
I want to implement versioning on my entity Stuff . Each entity has an optional reference to the next version (the latest version will be null) and an optional reference to the previous version (the first version will be null). I am using entity framework 6, code first. I tried with the following model and modelbuilder statement (and many variations). public class Stuff { public int StuffId { get; set; } [ForeignKey("NextVersion")] public int? NextVersionId { get; set; } [InverseProperty("PreviousVersion")] public virtual Stuff NextVersion { get; set; } public virtual Stuff PreviousVersion {

django.db.utils.IntegrityError: FOREIGN KEY constraint failed while executing LiveServerTestCases through Selenium and Python Django

落爺英雄遲暮 提交于 2019-12-05 17:46:09
I can run all unit tests successfully, I can even run selenium tests successfully if I run an independent server, but when I try to use LiveServerTestCases to test everything in a self-contained manner, each LiveServerTestCase test ends with the following error after completing the tearDown function: File "C:\Users\Win7\.virtualenvs\lang-QbOXb8q_\lib\site-packages\django\db\backends\base\base.py", line 239, in _commit return self.connection.commit() django.db.utils.IntegrityError: FOREIGN KEY constraint failed The above exception was the direct cause of the following exception: Traceback (most

why foreign key doesn't work in websql..?

梦想与她 提交于 2019-12-05 17:20:15
i try to use foreign key in my app using web sql.. i test it in chrome.. no error.. but when i test with manual insert to table img (contain FK) i expect to fail.. but insert is still succes.. this is my code.. please help me.. tx.executeSql("PRAGMA foreign_keys = ON;"); tx.executeSql("CREATE TABLE IF NOT EXISTS img (ID INTEGER PRIMARY KEY ASC,imgID VARCHAR, image VARCHAR, FOREIGN KEY (imgID) REFERENCES trans (ID) )", []); i this case i try to use FK method for save my image name data and connect to trans table.. my insert code tx.executeSql("insert into img (imgID,image) values ('100','23.jpg

MySQL Foreign Key, Can't create table (errno: 150)

左心房为你撑大大i 提交于 2019-12-05 16:48:56
问题 I am trying to build the database and tables for my system. But I found that if I don't add the foreign key in the codes. There is no error. I've used many method try to make the codes works, but it still have error. I am using MySQL 5.5.31, and the codes here: CREATE DATABASE TOS; DROP TABLE TOS.USER CASCADE; DROP TABLE TOS.BILL_HEADER CASCADE; DROP TABLE TOS.TOY CASCADE; CREATE TABLE TOS.USER (User Char(8), Name Char(10), Type Char(1), Password Char(12), PRIMARY KEY(User)); CREATE TABLE TOS

RestKit: Creating stubs for foreign key relationships

筅森魡賤 提交于 2019-12-05 15:52:20
I am struggling to map the foreign key relationships returned by my JSON API with RestKit. Specifically, I use Loopback to generate an API with Entities like Team and User . There are two Endpoints by default that return the following JSON: /Teams/ [ { "title": "Team Title", "id": 1, } ] /Users/ [ { "name": "Alice", "id": 1, "teamId": 1, }, { "name": "Bob", "id": 2, "teamId": 1, }, ... ] Now this is a pretty simple API, right? It should be easy to map with RestKit, but even after reading all those other questions about the topic (e.g. Seeking recommendations for best RestKit/CoreData mapping

Query is resulting in 1 row with null values when id is not found

六月ゝ 毕业季﹏ 提交于 2019-12-05 14:42:55
The exact query: SELECT coupon_coupons . code , coupon_coupons . discountType AS 'type', coupon_coupons . discountAmount AS 'amount', coupon_coupons . discountApplied AS 'applied', coupon_coupons . description , group_concat( coupon_targetsku . sku separator ';') AS 'targetsku' FROM coupon_coupons LEFT JOIN coupon_targetsku ON coupon_coupons . code = coupon_targetsku . code WHERE coupon_coupons . code = 'testCode' coupon_coupons.code = primary key coupon_targetsku.code = fk(coupon_coupons.code) If the coupon_coupons . code is found in the database the query operates as expected, but when its

Ignore MySQL foreign key constraints in PHP

青春壹個敷衍的年華 提交于 2019-12-05 13:42:20
问题 Is there a way to override mysql foreign key constraints in a php script? I have a query passed to mysql from php, but it fails a foreign key constraint, is there any way to get around this without altering the db schema? I'm just doing some testing, so I'll be removing the row when I'm done. 回答1: mysql_query('SET foreign_key_checks = 0'); //do some stuff here mysql_query('SET foreign_key_checks = 1'); 回答2: You can execute that MySQL query to disable foreign keys check: SET FOREIGN_KEY_CHECKS

What Does Rails Do With Both :dependent => :destroy and cascade delete/nullify/restrict

落爺英雄遲暮 提交于 2019-12-05 13:32:09
问题 I'm trying to decide how best to set up (if at all) foreign key constraints for my rails application. I have a model Response that belongs_to a Prompt . I would like to use :dependent => :destroy to have destroy called on every Response that belongs to a deleted Prompt and I'm trying to decide what delete constraint I should place on my foreign key. In short I want advice about how I can get best take advantage of both the destroy method on dependent objects and foreign key constraints to

Dynamically limit choices for Foreignkey in Django models based on another foreign key in the same model

家住魔仙堡 提交于 2019-12-05 13:18:31
I have these models: class UserProfile(models.Model): name = models.CharField(max_length=100) class Dialog(models.Model): belong_to = models.ManyToManyField(UserProfile) class Message(models.Model): # Dialog to which this message belongs part_of = models.ForeignKey(Dialog) # User who sends message sender = models.ForeignKey(UserProfile, related_name='sender') # User who receives message receiver = models.ForeignKey(UserProfile, related_name='receiver') What I want to do is limit the choices for the sender and receiver fields so that they can only be the users to which the whole dialog belongs.