foreign-key-relationship

Django change foreign key data and save

心不动则不痛 提交于 2019-12-13 07:12:49
问题 I have two models like class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) email = models.EmailField() class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateField() reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE) Now for an object of Article lets say a=Article.objects.filter(id=1) a=a[0] I try to change the headline and the email of the author who has written this

Hibernate delete row and foreign key row ManyToOne

拟墨画扇 提交于 2019-12-13 03:57:27
问题 I have the following two classes, one ReqCandAssociation can have many Comments and it is mapped like so. I need to figure out a way that when I delete a ReqCandAssociation it deletes all of its associated comments. Thanks @Entity @Table(name = "candidate_jobReq") public class ReqCandAssociation implements Serializable { @Id private Integer candidateId; @Id private Integer jobId; @Column(name = "reqStatus") private String reqStatus; @ManyToOne @PrimaryKeyJoinColumn(name="candidateId",

Problems with database relations with symfony framework - Cannot fetch TableMap for undefined table

老子叫甜甜 提交于 2019-12-13 03:00:56
问题 Currently developing an application using the newest version of symfony, obtained through PEAR. This is my exact schema configuration propel: user: id: name: { type: varchar(255), required: true } level: { type: integer, required: true, default: 1 } created_at: post: id: title: { type: varchar(255), required: true } post: { type: longvarchar, required: true } user_id: created_at: updated_at: comment: id: relation: integer comment: { type: varchar(300), required: true } nick: { type: varchar

SQL Server: Unable to create relationship

ぐ巨炮叔叔 提交于 2019-12-13 02:57:48
问题 I was trying to create a table that has a one to many relationships. but it seems that adding a foreign key in Personal is not working. I am trying to link a Personal Information table to a address table? what is the solution for this error? Address table saved successfully Personal table Unable to create relationship 'FK_Personal_Address'. Cascading foreign key 'FK_Personal_Address' cannot be created where the referencing column 'Personal.ID' is an identity column. Could not create

Cannot add foreign key constraignt MySql

假装没事ソ 提交于 2019-12-13 02:21:26
问题 I am creating a database in MySQL for school. It has come up with the error 'cannot add foreign key constraint.' I have looked at other similar questions but cannot find out how it relates to my table. Please help! 回答1: Update your entries table like so: CREATE TABLE IF NOT EXISTS entries( entry_id INT UNSIGNED NOT NULL AUTO_INCREMENT, exam_date DATE NOT NULL, student_id INT REFERENCES students(student_id), subject_id INT REFERENCES subjects(subject_id), PRIMARY KEY(entry_id) ) 来源: https:/

How do I choose which column from the “foreign” table is displayed in the view?

梦想的初衷 提交于 2019-12-13 01:39:14
问题 I am building a simple ASP.NET MVC app with Entity Framework Database First that allows a user to edit tables in a database. One table has a foreign key to another table. I want the user to be able to change the foreign key value. My question: How do I choose which column from the "foreign" table is displayed to the user in the view? I scaffolded the view out, but it is displaying the wrong column. The foreign key is in the DealerAuto table, which has columns: DealerAutoID, DealerID,

How to get image connected by Foreign Key via Template in django

浪子不回头ぞ 提交于 2019-12-13 01:06:33
问题 i want to get the images form the image model in the template. class Products(models.Model): category = models.ForeignKey(Category) name= models.CharField(max_length=120, unique=True) slug = models.SlugField(unique = True) price = models.IntegerField(default=100) class Image(models.Model): property = models.ForeignKey(Products, related_name='images') image = models.ImageField(upload_to='static/images/home',blank=True,null=True) views.py def index(request): queryset = Products.objects.all()

How to order by in Rails?

情到浓时终转凉″ 提交于 2019-12-12 19:13:15
问题 I'm working on a small blog engine. There are the following tables: Blog and Message. Blog has a foreign key: last_message_id, so I access the last message in the blog by calling blog.last_message I have the following code to make it work: class Blog < ActiveRecord::Base belongs_to :last_message, :class_name => "Message" end I need to order the blogs by the last messages. But when I call blogs.order("last_message.created_at DESC") It doesn't work. I get the following error: PGError: ERROR:

NHibernate many-to-one mapping: If parent is null, set foreign-key as empty Guid instead of null

谁都会走 提交于 2019-12-12 16:59:50
问题 What I am trying to is really quite straigh forward, but I cannot seem to get the mapping right with NHibernate. I am working up against a database with parent and child objects. The child objects have a foreign key reference to the primary key of the parent which is of datatype Guid. Pretty normal in any case. Now the database is set up in such a way that the foreign key field must never be null, so in case of orphan objects, with no parent, the foreign key should be an empty Guid ('00000000

One-to-one relationsip with optional dependent end using default conventions

吃可爱长大的小学妹 提交于 2019-12-12 14:05:05
问题 I'd like to have a principal entity ( Person ) with optional dependent entity ( Car ) mapped using the default conventions in Entity Framework code-first model. One solution is described in this answer, which uses the fluent API on modelBuilder to map to the key. Is it possible to do this using only the default EF conventions? The following code will throw a Unable to determine the principal end of an association between the types Person and Car. invalid operation exception. public