foreign-keys

Is it possible to have a MySQL column containing multiple values as foreign keys?

喜夏-厌秋 提交于 2019-12-08 07:08:38
问题 I am learning MySQL and have MariaDB installed in Fedora 19. I have a scenario where I require a column to contain multiple values in order to reduce possible redundancy of column allocation. In the example below, is it possible to have each value in the tags column of the log table reference the tag_id column in the tags table? users user_id | 1 | activities activitity_id | 1 log user_id | activity_id | tags 1 | 1 | 1,3,5 # multiple foreign keys? tags tag_id | 1 | 2 | 3 | 4 | 5 | If it is

Django query : Call values() on user__userprofile

偶尔善良 提交于 2019-12-08 07:00:54
问题 I have the following models: class UserProfile(models.Model): user = models.OneToOneField(User) score = models.PositiveIntegerField() class Game(models.Model): name = CharField(max_length=100) class Achievement(models.Model): user = models.ForeignKey('User') game = models.ForeignKey(Game) In settings.py I have set AUTH_PROFILE_MODULE to my UserProfile class. For a given game, I want to get a list of the users who have, say, more than five achievements for that game. So what I did was the

Self-referencing a partial key of a table

☆樱花仙子☆ 提交于 2019-12-08 06:44:28
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 nominee. I add a uniquifier to the table. I would like to assume that all registered shareholders and

Get access to ForeignKey objects at parent save in Django

寵の児 提交于 2019-12-08 06:35:35
问题 I am trying to make a combined image of all images added to a modell in django with inline editing and a ForeignKey. Ive got these models (simplified): class Modell(models.Model): title = models.CharField('beskrivelse', max_length=200) slug = models.SlugField() is_public = models.BooleanField('publisert', default=True) def __unicode__(self): return self.title def save(self, **kwargs): super(Modell, self).save(**kwargs) on_modell_saved(self) class Image(models.Model): modell = models

MySQL Foreign Key “ON DELETE CASCADE” across 3 tables

人盡茶涼 提交于 2019-12-08 06:21:08
问题 I have 3 tables in my DB (there are more, but there are no connections to these yet) table "molecule" with column id table "descriptor" with columns "id" and "molecule_id" and a foreign key referencing "molecule.id" table "tDepDescriptor" with columns "id" and "descriptor_id" and a foreign key referencing "descriptor.id " (each table has more columns, but none of these act as foreign keys or anything like that) All foreign keys have "on delete cascade" specified, all ids are unsigned int(5).

org.hibernate.MappingException: Foreign key (FK12A711396456CA10:) must have same number of columns as the referenced primary key

会有一股神秘感。 提交于 2019-12-08 06:21:00
问题 I'm having this error at Netbeans in my Java code: org.hibernate.MappingException: Foreign key (FK12A711396456CA10:devolucion_master [devolucion_consecutivo])) must have same number of columns as the referenced primary key (devolucion [detalle_ticket_id,detalle_ticket_ticket_id,detalle_ticket_fondo_fijo_id,detalle_ticket_caja_id,consecutivo] I made a foreign key from DevolucionMaster to Devolucion, using "consecutivo" from Devolucion to my variable "consecutivo" for DevolucionMaster, the

Django admin list_display weirdly slow with foreign keys

こ雲淡風輕ζ 提交于 2019-12-08 06:03:42
问题 Django 1.2.5 Python: 2.5.5 My admin list of a sports model has just gone really slow (5 minutes for 400 records). It was returning in a second or so until we got 400 games, 50 odd teams and 2 sports. I have fixed it in an awful way so I'd like to see if anyone has seen this before. My app looks like this: models: Sport( models.Model ) name Venue( models.Model ) name Team( models.Model ) name Fixture( models.Model ) date sport = models.ForeignKey(Sport) venue = models.ForeignKey(Venue)

how can i modify foreign key?

[亡魂溺海] 提交于 2019-12-08 05:45:06
问题 I'm wondering if it's possible to modify a Foreign Key? FOREIGN KEY (member) REFERENCES scores (level) ON DELETE CASCADE, And I would like to change it to: FOREIGN KEY (member, subject) REFERENCES scores (level, subject) ON DELETE set null, Is it possible? 回答1: You cannot modify the key in a single statement, see the ALTER TABLE syntax, in which there is no ALTER CONSTRAINT available. You must use 2 ALTER TABLE statements to accomplish what you want. Delete the key in the first one using an

Entity Framework doesn't generate ApplicationUser foreign key

牧云@^-^@ 提交于 2019-12-08 05:23:37
问题 Note: for this question, I've simplified the models a bit. Im working on an ASP.NET Core MVC application (with Entity Framework Core). I have three models. I have an ApplicationUser (that extends from IdentityUser), I have an Activity model and I have a 'SignUp' model that has a foreign key to an activity and a foreign key to ApplicationUser. At least, that's the idea. The thing is, Entity Framework recognices the Activity FK as a FK, but not the applicationuser. That just becomes another int

filter conditions from an association

若如初见. 提交于 2019-12-08 04:37:43
问题 I have a search function, which works great for staff, so I can search by name. Now, I want filter staffs by staffgroup.groupname, but unfortunatelly i get this error: Column not found: 1054 Unknown column 'staffgroups.groupname' in 'where clause' I'm having the following tablelayout staffs (a person can belong to many groups) staff_staffgroups (HABTM-linking table) staffgroups (has a groupname) i used the conditions as follows: $tmpConditions['AND'][] = array('Staff.isActive =' => "1");