foreign-keys

Unable to update Foreign Key in Entity Framework 6

百般思念 提交于 2019-11-27 18:49:10
问题 I am trying to do a simple update to the foreign key but the script never get sent over. Here is the code I am using: using (var db = new MyContext()) { db.Entry<Contact>(newContact).State = EntityState.Modified; newContact.ContactOwner = db.Person.Find(3); db.SaveChanges(); } EF6 update the rest of the column in the Persons table but it is not updating the Contact_Id in Persons table. Person entity: public class Person { public int Id { get; set; } public string Name { get; set; } public

How to remove duplicate rows with foreign keys dependencies?

一个人想着一个人 提交于 2019-11-27 18:47:03
问题 I'm sure this is common place, but Google is not helping. I am trying to write a simple stored procedure in PostgreSQL 9.1 that will remove duplicate entries from a parent cpt table. The parent table cpt is referenced by a child table lab defined as: CREATE TABLE lab ( recid serial NOT NULL, cpt_recid integer, ........ CONSTRAINT cs_cpt FOREIGN KEY (cpt_recid) REFERENCES cpt (recid) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE RESTRICT, ... ); The biggest problem I'm having is how to obtain the

Meaning of “n:m” and “1:n” in database design

懵懂的女人 提交于 2019-11-27 18:40:49
In database design what do n:m and 1:n mean? Does it have anything to do with keys or relationships? m:n is used to denote a many-to-many relationship ( m objects on the other side related to n on the other) while 1:n refers to a one-to-many relationship ( 1 object on the other side related to n on the other). 1:n means 'one-to-many'; you have two tables, and each row of table A may be referenced by any number of rows in table B, but each row in table B can only reference one row in table A (or none at all). n:m (or n:n) means 'many-to-many'; each row in table A can reference many rows in

MySQL: How to determine foreign key relationships programmatically?

白昼怎懂夜的黑 提交于 2019-11-27 18:37:07
Similar to this question but for MySQL.... How can I programmatically determine foreign key references in MySQL (assuming InnoDB)? I can almost get them with: SHOW TABLE STATUS WHERE Name = 'MyTableName'; ...but alas, the comment column which seems to contain some of this info gets truncated so I can't rely on it. There must be some other way... I'd be happy with a C API call, a SQL statement, anything--I just need something that consistently works. Note: I've also considered parsing the results of a "SHOW CREATE TABLE MyTableName" statement, but I'm really hoping there's something simpler.

Inline-like solution for Django Admin where Admin contains ForeignKey to other model

拜拜、爱过 提交于 2019-11-27 18:36:37
I have several Customer s who book Appointment s. Each Appointment has exactly one customer, though a customer can be booked for multiple appointments occurring at different times. class Customer(model.Model): def __unicode__(self): return u'%s' % (self.name,) name = models.CharField(max_length=30) # and about ten other fields I'd like to see from the admin view. class Appointment(models.Model): datetime = models.DateTimeField() customer = models.ForeignKey("Customer") class Meta: ordering = ('datetime',) Now when an admin goes to browse through the schedule by looking at the Appointments

Django model with 2 foreign keys from the same table

巧了我就是萌 提交于 2019-11-27 18:19:44
I wanted a Django model with 2 foreign keys from the same table. It's an event table which has 2 columns for employees: the 'actor' and the 'receiver'. But I get this error: Error: One or more models did not validate: tasks.task: Intermediary model TaskEvent has more than one foreign key to Employee, which is ambiguous and is not permitted. Is there a better way to model this? Thanks I think I'm going to add a TaskEvent_to_Employee table. There will be two records in it, one for each of the two employees related to each TaskEvent . Anyone know an easier workaround? I haven't done this yet, but

How to use BULK INSERT when rows depend on foreign keys values?

安稳与你 提交于 2019-11-27 18:11:28
问题 My question is related to this one I asked on ServerFault. Based on this, I've considered the use of BULK INSERT. I now understand that I have to prepare myself a file for each entities I want to save into the database. No matter what, I still wonder whether this BULK INSERT will avoid the memory issue on my system as described in the referenced question on ServerFault. As for the Streets table, it's quite simple! I have only two cities and five sectors to care about as the foreign keys. But

Django admin: Change selected box of related fields to autocomplete

纵饮孤独 提交于 2019-11-27 18:02:28
We have some models that are have a user as a foreign key. But with about 25000 users in our system, it's a bit daunting to find the one we need. Is there a solution out there that's better than the select box? Maybe an autocomplete so we can start typing the user name / address? Or just a search box? When switching the related user for these objects, it's getting harder and harder with 25000 unsorted users. Even just setting it to sort the users by username would be helpful. Etienne I had this problem and my conclusion was to use an autocomplete field instead. It works pretty well in most

SQlite - Android - Foreign key syntax

心不动则不痛 提交于 2019-11-27 17:57:54
I've been trying to get foreign keys working within my Android SQLite database. I have tried the following syntax but it gives me a force close: private static final String TASK_TABLE_CREATE = "create table " + TASK_TABLE + " (" + TASK_ID + " integer primary key autoincrement, " + TASK_TITLE + " text not null, " + TASK_NOTES + " text not null, " + TASK_DATE_TIME + " text not null, FOREIGN KEY ("+TASK_CAT+") REFERENCES "+CAT_TABLE+" ("+CAT_ID+"));"; Any ideas what I might be doing wrong? if you need to see the other table structure then I can, its just a very simple structure for the second

Linq To SQL Without Explicit Foreign Key Relationships

旧街凉风 提交于 2019-11-27 17:41:10
问题 I am working with a few legacy tables that have relationships, but those relationships haven't been explicitly set as primary/foreign keys. I created a .dbml file using "Linq To Sql Classes" and established the proper Case.CaseID = CaseInfo.CaseID association. My resulting class is CasesDataContext. My Tables (One to many): Case ------------------ CaseID (int not null) MetaColumn1 (varchar) MetaColumn2 (varchar) MetaColumn3 (varchar) ... CaseInfo ------------------ CaseInfoID (int) CaseID