foreign-key-relationship

mysql foreign key “permissions” on delete

那年仲夏 提交于 2019-12-12 03:14:19
问题 I'm working on a little support (ticket) system. My tables are tickets and ticket_replies. Design of tickets table is id|user_id|title|... Design of ticket_replies looks like: id|ticket_id|... The foreign key I added looks like this: ALTER TABLE `ticket_replies` ADDFOREIGN KEY (`ticket_id`) REFERENCES `sampleauth`.`tickets`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; Now when I delete a "ticket" in the "ticket" table it gets deleted in "ticket_replies" too. The other way this doesn't work, all

An image table to serve two foreign tables?

不打扰是莪最后的温柔 提交于 2019-12-12 02:57:55
问题 I have this image table , image_id image_title image_description image_source and I want this image table to associate with page table and sometimes with comment table page table, page_id ... ... comment table, comment_id ... ... Should I put the foreign key of page_id and comment_id in image table? image_id image_title image_description image_source page_id comment_id Or should I create a map table for each purpose? a map table for image and page image_id page_id and another map table for

Introducing FOREIGN KEY may cause cycles or multiple cascade paths

孤街醉人 提交于 2019-12-12 02:49:26
问题 i am using Entity Framework with code first approach. In my onModelCreating I am creating my tables with keys and relationships (I am using Fluent API approach, not data annotations). But when I try to generate my model using Update-Database command I receive following error Introducing FOREIGN KEY constraint 'FK_customers.invoices_customers.billingCenters_billingCenterId' on table 'invoices' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or

Configuring multiple 1 to 0..1 relationships between tables entity framework

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:32:29
问题 Following on from earlier posts today: Entity framework one to zero or one relationship without navigation property Understanding ForeignKey attribute in entity framework code first I'm now trying to configure the following relationships: Item1 has optional RawData Item2 has optional RawData Item3 has optional RawData RawData must be attached to either Item1, Item2 or Item3 - it would not be expected to exist on its own. Current structure is: class ItemX { [Key] public int Id { get; set; }

How do I remove redundancy from this database layout's 1:M relationship and still be able to excerpt the data needed?

邮差的信 提交于 2019-12-11 19:36:39
问题 The database looks like this: CREATE TABLE artists ( artist_id SERIAL PRIMARY KEY, artist TEXT UNIQUE NOT NULL ); CREATE TABLE artistalias ( artistalias_id SERIAL PRIMARY KEY, artist_id SERIAL REFERENCES artists (artist_id), alias TEXT UNIQUE NOT NULL ); CREATE TABLE songs ( song_id SERIAL PRIMARY KEY, song TEXT NOT NULL, artist_id SERIAL REFERENCES artists (artist_id) ); one artist can have zero, one or many aliases one alias belongs to exactly one artist one song has one artist one artist

JPA Hibernate null pointer exception with OneToOne primary key/foreign key type relation

不问归期 提交于 2019-12-11 16:08:28
问题 I'm having lots of trouble with a little prototype I'm trying to build. The problem involves two entities. But to understand it, I will need to describe a few others. In terms of the database structure, it can be described as follows: Person ---------------- id Integer PK surname VARCHAR givenNames VARCHAR TypedIdentifier ---------------- idCode VARCHAR PK FK (IdType.code) idVal VARCHAR PK person Integer FK (Person.id) IdType ------ code VARCHAR PK IdDescription ---------- code VARCHAR PK FK

mysql Getting the same auto_increment value into another

痞子三分冷 提交于 2019-12-11 16:04:52
问题 This may have a really easy answer. I have done much database stuff for a while. I am trying to get the auto_increment value from one table inserted into the value on another table. is there an easy way of doing this. For eg i have done: CREATE TABLE table_a ( id int NOT NULL AUTO_INCREMENT, a_value varchar(4), PRIMARY KEY (id) ); CREATE TABLE table_b ( id int NOT NULL, b_value varchar(15), FOREIGN KEY (id) REFERENCES table_a (id) ); Now i want to insert values into the table but I would like

“The DELETE statement conflicted with the REFERENCE constraint” while there is no data in referenced table

落爺英雄遲暮 提交于 2019-12-11 15:48:40
问题 I have two related tables: [GameDataGroup] with PK [Arena_GameData] with FK I try to execute query: DELETE FROM [ACP_MAIN_STABLE_DB_content].[dbo].[GameDataGroup] WHERE [key] LIKE '%' + '_test_group' + '%' And have a message: The DELETE statement conflicted with the REFERENCE constraint "FK__Arena_GameData__GameDataGroup". The conflict occurred in database "ACP_MAIN_STABLE_DB_content", table "dbo.Arena_GameData", column 'gameDataGroupId'. While there is no related data in "dbo.Arena_GameData"

Query a table by using foreign key navigation properties in LINQ with C#

你离开我真会死。 提交于 2019-12-11 15:15:07
问题 I have the following LINQ to SQL EF classes: with the foreign key relationship on SessionId (primary table WebinarSession ). I would like, by using lambdas to select all the WebinarSession rows that concern a specific product line. I put as example this code that of course DOES NOT WORK (it would owrk with Single inseatd of Where but it is not applicable because I have mulitple instances matching the condition): SessionId = _webinarRecordingsDB.WebinarSessions.Where(m => m.SessionId == m

How do I make sure each post in the Post feed shown in the home page has all its comments displayed under it?

半城伤御伤魂 提交于 2019-12-11 14:33:53
问题 I have a Post model, and a Comment model that belongs to Post. I was able to display the Post in the home view corresponding to the home controller and home action and the User/show view. Thus, in the home and user views, the posts are listed in order of creation time. I was also able to have a post form in both the user and home views and a comment form in the home and user views. The problem arises when I try to display the comment underneath each displayed Post in the home and user views.