foreign-keys

Linq to sql - delete some related records

拥有回忆 提交于 2019-12-10 14:56:04
问题 I´m using linq to sql and I have a lot of tables with foreign keys leading to the UserId. Is it possible to have some of these foreign tables cleaned upon deletion. For example I want the users profile (other table) to be deleted automatically with the user but not the users forum posts. Is this possible or do I have to handle this with code? 回答1: I think this link is very usefull. LINQ to SQL does not support or recognize cascade-delete operations. If you want to delete a row in a table that

Creating foreign key on same table SQLite

会有一股神秘感。 提交于 2019-12-10 14:50:05
问题 Recently I started using SQLite (as required for my study) and I came accross a couple of restrictions of SQLite and I was wondering: can't SQLite create foreign keys on the same table? E.g. this is my code: CREATE TABLE Categories ( name varchar(20), parent_category varchar(20) NULL, PRIMARY KEY(name), FOREIGN KEY parent_category_fk(parent_category) REFERENCES Categories(name) ) But it gives me an error for the foreign key when I try to execute the SQL in SQLiteStudio. Does anyone know why

How to represent Foreign Key relationships in Core Data - Data Model in XCode

混江龙づ霸主 提交于 2019-12-10 13:44:29
问题 Totally new with Core Data, I'm making my data model. I have 33 entities, and few hard relationships between them but lots of Foreign-Key relationships. How can I manage that relationships that are not exactly 1-many or 1-1 or many-many but are foreign keys in Core Data Model? For ex., I have a Contact entity, which has a relationship with a contact_x_mail, and at the same time contact_x_mail has a relationship with Mail, that contains all emails. This relationships are 1-many or many-many.

Two-way foreign key constraint in a 1:1 relation

天涯浪子 提交于 2019-12-10 13:40:46
问题 I am using a MySQL database. In my relational data model, I've got two entities that relate 1:1 to each other. In my schema, a 1:1 relation is set up by putting a FK field in one of the two tables, that relates to the PK of the other table. Both tables have PKs and they are both auto increment BIGINTs. I am wondering whether it would be possible to have an ON DELETE CASCADE behaviour on them that works both ways. i.e. A 1:1 B, means that [ deleting A also deletes B ] as well as [ deleting B

Oracle optional relationship

扶醉桌前 提交于 2019-12-10 13:20:03
问题 What is the proper way to define an oracle table who has an optional foreign key relationship with another table? For instance, some employee records have defined the country they are from (a FK from countries table), and some have not. 回答1: Just allow the column to be nullable (don't make it NOT NULL ) and create your foreign key as normal. The database will enforce the foreign key for any rows that contain a value in that row, but nothing will be enforced if the row is null. 来源: https:/

Entity Framework .net: “The Name value should be a valid navigation property name.”

ぐ巨炮叔叔 提交于 2019-12-10 13:13:26
问题 Hello I'm starting a project with ASP.Net and I'm following the Training Camps of Microsoft. I was trying to make a REST petition to my published api, and I got the next exception: The ForeignKeyAttribute on property 'QuestionId' on type 'PlataformaTest.Models.AnswerModel' is not valid. The navigation property 'OptionModel' was not found on the dependent type 'PlataformaTest.Models.AnswerModel'. The Name value should be a valid navigation property name.","exceptionType":"System

Laravel 5.1 foreign keys in model factory

孤街醉人 提交于 2019-12-10 13:10:00
问题 How do you define foreign keys in a model factory. For example if I have a organisations table which has a foreign key to the countries table, in my model factory I'm having to define a dummy value for the country id as follows: $factory->define(App\Organisation::class, function ($faker) { return [ 'name' => $faker->company, 'country_id' => 197, ]; }); In my organisations table seeder class I am doing the following but the faker object isn't present - do I need to create a new faker object in

Adding Foreign Key Fails in MySQL (errno 150)

不问归期 提交于 2019-12-10 12:45:07
问题 I've read many other posts about receiving MySQL errno 150 when trying to add a foreign key copnstraint, however I haven't found a solution yet. I hope I'm not doing something stupid. I made a simple test case. Both tables are InnoDB. Both tables are UTF-8. Both columns are int(11) unsigned (making color_id NOT NULL doesn't make a difference). ( EDIT: I WAS WRONG ABOUT THIS, AND THIS WAS THE SOLUTION ) Here are my two tables: Table widgets : CREATE TABLE `widgets` ( `id` int(11) unsigned NOT

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

Self-referencing a partial key of a table

青春壹個敷衍的年華 提交于 2019-12-10 11:38:02
问题 I am designing a datatable (-s) for storing the list of shareholders. In case a shareholder is a nominee, it discloses the list of share owners. These all need to have a pile of similar references. Thus, I would like to store all in one table. Nominees are registered shareholders and thus, they have an account number in the system, from which I get the data. Opposed to this, share owners that are coming from nominee disclosure have no their own account number, and share account number of the