foreign-keys

JPA/hibernate - Cannot add or update a child row: a foreign key constraint fails - BUT record exists

不羁岁月 提交于 2020-01-13 17:03:09
问题 I'm having a strange problem. I have some records in the database: Company id = 1, Name = Microsoft id = 2, Name = Sun Now I have another entity, Event which has a foreign key reference to Company: @Entity public class Event { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @ManyToOne private Company company; } In my web service layer, I create an Event using a company ID passed as a URL param: @GET @Path("addEvent") public String addEvent(@QueryParam("cid") long companyId)

phpmyadmin and foreign keys

假如想象 提交于 2020-01-13 10:25:08
问题 I added a foreign key constraint to one of my fields. On insert, the field is showing up as a drop down instead of a text box, as expected. But the drop down has each value listed twice, once with a minus sign before the value and once with the minus sign after the value. Like this: - value1 - value2 - value3 value1 - value2 - value3 - What does this mean? 回答1: Phpmyadmin by default shows foreign key value and a custom description field next to it (which is set in "Relation view" for the

referential integrity in rails

社会主义新天地 提交于 2020-01-13 05:17:07
问题 So, I just came across the fact that rails does not support referential integrity regarding foreign keys and was fairly surprised. So, what's the best way to manage this? Is there a "rails" way for dealing with referential integrity? Ideally the app should not have to deal with all this; the db should. I was looking at plugins like foreigner. I wonder if this method has some shortcomings. How is this normally dealt with in rails? 回答1: It's a design decision for Rails ActiveRecord. I consider

DELETE all where MySQL foreign key constraint does not fail

ぐ巨炮叔叔 提交于 2020-01-12 14:03:11
问题 I am trying to delete a few records but am getting the following error: Cannot delete or update a parent row: a foreign key constraint fails The thing is, the foreign key constraint is failing for only 1 or 2 of my 100 records I wish to delete. I wish to write a query which deletes these 98-99 records, skipping the 1 or 2 which failed , which I can later manually inspect and delete/modify. Not stopping because of some single problematic record, but continuing with the others, ignoring that.

DELETE all where MySQL foreign key constraint does not fail

て烟熏妆下的殇ゞ 提交于 2020-01-12 14:02:31
问题 I am trying to delete a few records but am getting the following error: Cannot delete or update a parent row: a foreign key constraint fails The thing is, the foreign key constraint is failing for only 1 or 2 of my 100 records I wish to delete. I wish to write a query which deletes these 98-99 records, skipping the 1 or 2 which failed , which I can later manually inspect and delete/modify. Not stopping because of some single problematic record, but continuing with the others, ignoring that.

SQL error: “name already used by an existing constraint”

谁说胖子不能爱 提交于 2020-01-11 14:39:11
问题 I'm trying to create some tables and setup the foreign keys but I keep encountering problems with the foreign keys. Earlier on I created the below table and it works fine CREATE TABLE inpatient (PatientNo varchar(6) NOT NULL, WardNo number(2), BedNo number(3) NOT NULL, OnWaitingList date, WardRequired varchar(25), ExpectStayInDays number(4), DatePlaced date, DateLeave date, ActualLeave date, constraint PatientFK foreign key (PatientNo) references Patient (patientNo), constraint bedFK foreign

Foreign key issue:ERROR 1005 (HY000): Can't create table (errno: 150)

核能气质少年 提交于 2020-01-11 13:04:11
问题 I'm getting this error: ERROR 1005 (HY000): Can't create table (errno: 150); I know it has something to do with the foreign keys but I have checked to see if they have the same info types etc and I can't find the problem. The video, director actor, role and member create; the rest do not. CREATE TABLE IF NOT EXISTS actor ( actorNo VARCHAR(15) NOT NULL, actorName VARCHAR(40) NOT NULL, PRIMARY KEY (actorNo) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS staff ( StaffNo VARCHAR (15) NOT NULL, name

Foreign key issue:ERROR 1005 (HY000): Can't create table (errno: 150)

空扰寡人 提交于 2020-01-11 13:04:03
问题 I'm getting this error: ERROR 1005 (HY000): Can't create table (errno: 150); I know it has something to do with the foreign keys but I have checked to see if they have the same info types etc and I can't find the problem. The video, director actor, role and member create; the rest do not. CREATE TABLE IF NOT EXISTS actor ( actorNo VARCHAR(15) NOT NULL, actorName VARCHAR(40) NOT NULL, PRIMARY KEY (actorNo) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS staff ( StaffNo VARCHAR (15) NOT NULL, name

How does SqlBulkCopy circumnavigate foreign key constraints?

陌路散爱 提交于 2020-01-10 11:49:28
问题 I used SqlBulkCopy to insert a collection of rows into a table. I forgot to set an integer value on the rows. The missing column is used to reference another table and this is enforced with a foreign key constraint. For every row inserted, the final integer value was zero and zero didn't identify a row in the related table. When I modified the value to a valid value and then tried to switch it back to zero it wouldn't accept it. So my question is how does SqlBulkCopy manage to leave the

How does SqlBulkCopy circumnavigate foreign key constraints?

本小妞迷上赌 提交于 2020-01-10 11:49:05
问题 I used SqlBulkCopy to insert a collection of rows into a table. I forgot to set an integer value on the rows. The missing column is used to reference another table and this is enforced with a foreign key constraint. For every row inserted, the final integer value was zero and zero didn't identify a row in the related table. When I modified the value to a valid value and then tried to switch it back to zero it wouldn't accept it. So my question is how does SqlBulkCopy manage to leave the