foreign-key-relationship

Entity Framework 5 - code first array navigation property one to many with Interface Type

寵の児 提交于 2020-05-13 08:03:11
问题 These are my classes: public class Post : IPost { public int Id { get; set; } public virtual int[] DuplicateOf { get; set; } public virtual ICommentInfo[] Comments { get; set; } } public class CommentInfo : ICommentInfo { public virtual string Author { get; set; } public virtual int Id { get; set; } public virtual string Text { get; set; } public virtual int PostId{ get; set; } [ForeignKey("PostId")] public virtual Post Post { get; set; } } With this CommentConfiguration added to

MySQL Big FK identifier

懵懂的女人 提交于 2020-01-25 07:06:47
问题 I'm trying to create a fk but MySQL doesn't allow it ... Identifier name 'foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY' is too long [ CREATE TABLE `foobarbaz_weee_discount` ( `entity_id` int(10) unsigned NOT NULL DEFAULT '0', `website_id` smallint(5) unsigned NOT NULL DEFAULT '0', `customer_group_id` smallint(5) unsigned NOT NULL, `value` decimal(12,4) NOT NULL DEFAULT '0.0000', KEY `foobarbaz_FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_WEBSITE` (`website_id`), KEY `foobarbaz

Primary Key Resetting Issue with foreign keys and delete

半城伤御伤魂 提交于 2020-01-22 02:50:09
问题 I have a set of tables which I am going to clear out and upload new data into. One of these, Person has foreign keys pointing to it which prevent me from using TRUNCATE Table even though the other tables are empty. I have used DELETE FROM after turning off the foreign key checks to get around this. This works except when I insert new values they start at the old value going up and I need them to reset to start at 1 again (or at least some consistent predictable value) DBCC CHECKIDENT ([Person

Entity Framework Code First: 1:0..1 Change Foreign Key Location

北战南征 提交于 2020-01-17 14:51:25
问题 I have a 1-to-0..1 relationship defined in an Entity Framework code first model like this: public class Album { public int AlbumId { get; set; } public int StampId { get; set; } public Stamp Stamp { get; set; } // other properties } public class Stamp { public int StampId { get; set; } public int AlbumId { get; set; } [Required] public Album Album { get; set; } // other properties } So.. an album has 0..1 stamps, a stamp always has exactly one album. The configuration I have here works nicely

Database schema for managing addresses

不问归期 提交于 2020-01-17 14:47:25
问题 I am developing a MVC project with sql server. in which each user will be given a username after registration. Registration is done using various data like address and email number and phone number. I am using a table to store address and its id is stored in users table. Now as people can have change address so I'm not able to understand it how to manage it. I want to keep the old address as well as new for new users. Can anybody help? 回答1: You have some options: In address table, add userid

How do I override the cascade delete for a relation in Grails GORM?

我怕爱的太早我们不能终老 提交于 2020-01-14 19:38:27
问题 I'm having some problems with the GORM part of Grails. I am using Grails 1.3.4, together with H2. In the database I have two tables template and report . On the GORM-level I have the two Domain classes Template and Report ; class Template { static hasMany = [reports: Report] ... } and class Report { static belongsTo = [template: Template] ... } Default behaviour seems to be that when a Template is deleted, the deletion will be cascaded so that all Report s that it has will be deleted as well.

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.

How to duplicate schemas in PostgreSQL

我的梦境 提交于 2020-01-11 17:29:49
问题 I have a database with schema public and schema_A . I need to create a new schema schema_b with the same structure than schema_a . I found the function below, the problem is that it does not copy the foreign key constraints. CREATE OR REPLACE FUNCTION clone_schema(source_schema text, dest_schema text) RETURNS void AS $BODY$ DECLARE object text; buffer text; default_ text; column_ text; BEGIN EXECUTE 'CREATE SCHEMA ' || dest_schema ; -- TODO: Find a way to make this sequence's owner is the

How to set a foreign key which is dependent on the relation of other two tables?

我怕爱的太早我们不能终老 提交于 2020-01-07 14:02:12
问题 I have 3 tables; teachers table, subjects table and events table. 1.There is one to many relationship between subjects and teachers, that is each teacher can teach only one subject but, many teachers can teach same subjects. 2.There is a many to many relationship between teachers and events. Example of subjects table id(PK) | name ------------------- 1 | php ------------------- 2 | java ------------------- 3 | python ------------------- 4 | c++ -------------------- 5 | c# Example of teachers