foreign-key-relationship

Error while adding Foreign key

偶尔善良 提交于 2019-12-11 04:15:16
问题 I am using Mysql Workbench. I have already made the table. Now I want to add foreign key in a table called Personal_Details that key is primary key in Login table. But when I am trying to do so, it shows me the following error: ERROR 1005: Can't create table 'shaadiDB.#sql-404_25' (errno: 121) SQL Statement: ALTER TABLE `shaadiDB`.`Personal_Details` ADD CONSTRAINT `Login_Id` FOREIGN KEY (`Login_Id` ) REFERENCES `shaadiDB`.`Login` (`Login_Id` ) ON DELETE NO ACTION ON UPDATE NO ACTION , ADD

Foreign keys, where they belong depending on relationships

北战南征 提交于 2019-12-11 03:05:58
问题 I've worked with databases a fair bit ( MySQL, Oracle ) though typically only DML as the systems had been previously engineered. I'm working on a project as the sole developer, and am responsible for application development, and DBA; the latter of course proving more problematic. In any case - I need a refresh on foreign key constraints, and their logical placement in a model. Given the following: dbc_user .user_id INT, Primary Key, Auto Increment // arbitrary columns dbc_user_profile .user

MySql memory engine do not check on update foreign key?

旧时模样 提交于 2019-12-11 01:22:37
问题 After making a few tests, I found that foreign keys on MEMORY engine miss one of the checks for consistency. To explain better, here a similar example in InnoDb CREATE TABLE testInnoDb1 ( c1 int(11) PRIMARY KEY ) ENGINE=InnoDB; CREATE TABLE testInnoDb2 ( c1 int(11) PRIMARY KEY, FOREIGN KEY (c1) REFERENCES testInnoDb1(c1) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB; INSERT INTO testInnoDb1 (c1) VALUES (42); INSERT INTO testInnoDb2 (c1) VALUES (42); -- INSERT INTO testInnoDb2 (c1)

One table column for many fk tables?

断了今生、忘了曾经 提交于 2019-12-10 23:37:00
问题 What is the best solution/practice for situation like this? I have a table, that can reference to multiple tables (objects)? Here is an example for a table UserCalendar. It's a table where user saves his event, but also system inserts in this table from behind. User executes some services, which have deadlines and those are inserted in this table also. Problem is that there is no such a table as UserEvent table. User should save all his events in this calendar as description. I should make

django foreign key relation lookup

会有一股神秘感。 提交于 2019-12-10 19:45:23
问题 Given the following models: class Post(models.Model): title = models.CharField(max_length=200) html = models.TextField() class PostTag(models.Model): post = models.ForeignKey('Post') tag = models.CharField(max_length=200) I want to accomplish looking up a Post based on a given PostTag. So if I had two posts, A and B, tagged as "foo", I want to be able to look up all posts with that tag and get the posts A and B back. I image the query would look something like the following: posts = Post

If condition always routing towards hasError condition while submitting a form

懵懂的女人 提交于 2019-12-10 15:43:06
问题 I have created a simple form to add a shop, every shop has a manytoone relation with the member Shop.java model package models; @Entity public class Shop extends Model { @Id@SequenceGenerator(name = "shop_gen", sequenceName = "shop_id_seq", allocationSize = 1)@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "shop_gen")@Column(name = "id") public Long id; @Required public String name; @Required public String addressLine1; public String addressLine2; public String addressLine3;

Database Design - Column In One Table References Two Tables

谁说胖子不能爱 提交于 2019-12-10 15:38:33
问题 Here is an example of what I have (take Stack Overflow). I have 2 tables, Questions and Answers . I also have a Comments table. The Comments table will reference both Questions and Answers. How should I set up the database? Have 2 columns in Comments, a QuestionId and AnswerId. Have one table for both Questions and Answers? Have a table in between that somehow tells me Question or Answer? EDIT: Found the SO Data explorer, it uses one table for both Questions and Answers ... I just don't like

How to create foreign key relationships with the Entity Framework?

旧城冷巷雨未停 提交于 2019-12-10 14:23:39
问题 I want to create a new row in my database on a table that has a couple of foreign key relationships and I haven't been able to get a handle on what order and what calls need to be made. This is what I have so far: db.Models.Order order = DB.Models.Order.CreateOrder( apple ); order.CustomerReference.Attach( ( from c in db.Customer where c.Id == custId select c ).First() ); db.SaveChanges(); The code is failing on the second line there, saying: Attach is not a valid operation when the source

referencing multiple foreign keys php mysql

风格不统一 提交于 2019-12-10 11:41:56
问题 I'm very new to php/MySQL and I'm having a bit of trouble. Help would be much appreciated. I have 2 tables laid out as such: table team team_id,team_name table schedule game_id,game_time,team1_id,team2_id,location schedule.team1_id and schedule.team2_id are both foreign keys to team.team_id. I'm trying to reference team_name using team1_id and team2_id but I can only ever seem to get the name for team1. This is the query I've used unsuccessfully. SELECT * FROM team AS t JOIN schedule AS s ON

how to return a json response based on database relationship using eloquent

寵の児 提交于 2019-12-10 10:01:54
问题 I'm quite new to Laravel. I'm figuring out to work with Eloquent. Let's say I have 2 tables: categories and products. These two table have a one-to-many relationship. 1 category can have many products. I would like to return a JSON response which consists of an array of categories where each category has an array of products. It should look like this: [ {"name":"Category 1", "products": [ {"name":"Product 1","price":"2.50"}, {"name":"Product 2","price":"2.50"} ] }, {"name":"Category 2",