foreign-keys

How to populate a table's foreign keys from other tables

╄→гoц情女王★ 提交于 2019-12-05 12:52:45
I've got the following tables, of which translation is empty and I'm trying to fill: translation { id translated language_id template_id } language { id langname langcode } template { id tplname source domain total } The source data to fill translation is a temporary table that I've populated from an external CSV file: tmp_table { id translated langname tplname source domain } What I'd like to do is to fill translation with the values from tmp_table . The translated field can be copied directly, but I'm not quite sure how to fetch the right language_id (tmp_table.langname could be used to

Hibernate and H2 “Referential integrity constraint violation” for OneToMany bidirectional mapping

流过昼夜 提交于 2019-12-05 12:30:20
问题 So I have two simple beans -- FatKid and Hamburgers. Now, for reasons unbeknownst to me I need to be able to not only look up all of the hamburgers someone ate, but also who ate which particular hamburger. Onto the code! FatKid.java import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence

How to implement ONE-TO-MANY in a database

旧街凉风 提交于 2019-12-05 12:19:58
问题 I want to implement one-to-many concept in my application. This is the scenario: I have two tables (i). Person(ID, NAME, AGE, DEPT) (ii). Person Responsibilities(ID, RESP'S) One person may have more than one responsibility. How shall I implement a 1-n relationship here? Actually, I don't understand the correct concepts for this. Any suggestions or links to understand this concept would be appreciated. 回答1: This one-to-many relationship can be interpreted in plain English like this... A Person

Foreign Keys with SchemaExport in Fluent NHibernate using SQLite

会有一股神秘感。 提交于 2019-12-05 12:00:32
I am attempting to create a simple database application which keeps track of loans of various types of equipment using Fluent NHibernate and SQLite. However, when I try to generate the database structure with SchemaExport for use in unit testing, foreign keys for one-to-many relationships aren't created. Here is my Equipment entity: public virtual int Id { get; set; } public virtual EquipmentType Type { get; set; } public virtual int StockId { get; set; } And here are my mappings for Equipment : Id(x => x.Id); References(x => x.Type); Map(x => x.StockId); The SQL is generated correctly, except

Foreign key optimization in SQLite

泄露秘密 提交于 2019-12-05 10:27:02
问题 I know that SQLite does not enforce foreign keys natively, but that's not my primary concern. The question is: If I declare CREATE TABLE invoice ( invoiceID INTEGER PRIMARY KEY, clientID INTEGER REFERENCES client(clientID), ... ) will sqlite at least use the information that clientID is a foreign key to optimize queries and automatically index invoice.clientID, or is this constraint a real no-op? 回答1: Even if it is not actually a no-op (a data structure describing the constraint is added to

Rails model with foreign_key and link table

女生的网名这么多〃 提交于 2019-12-05 09:28:58
问题 I am trying to create a model for a ruby on rails project that builds relationships between different words. Think of it as a dictionary where the "Links" between two words shows that they can be used synonymously. My DB looks something like this: Words ---- id Links ----- id word1_id word2_id How do I create a relationship between two words, using the link-table. I've tried to create the model but was not sure how to get the link-table into play: class Word < ActiveRecord::Base has_many

FOREIGN KEY references same table's column. Can't insert values

五迷三道 提交于 2019-12-05 08:05:49
I created table with FOREIGN KEY and can't insert anything. CREATE TABLE menus ( id int(10), parent_id int(10), label varchar(255), PRIMARY KEY (id), FOREIGN KEY (parent_id) REFERENCES menus (id) ); I need FOREIGN KEY to automatically delete children when parent was deleted. This table was successfully created but I can't insert anything. INSERT INTO `menus` (`parent_id`, `label`) VALUES ('1', 'label1'); or INSERT INTO `menus` (`label`) VALUES ( 'label1'); #1452 - Cannot add or update a child row: a foreign key constraint fails I really don't want look for any children in php code so I need

django-admin formfield_for_* change default value per/depending on instance

大兔子大兔子 提交于 2019-12-05 07:53:05
问题 I'm trying to change the default value of a foreignkey-formfield to set a Value of an other model depending on the logged in user . But I'm racking my brain on it... This: Changing ForeignKey’s defaults in admin site would an option to change the empty_label, but I need the default_value. #Now I tried the following without errors but it didn't had the desired effect: class EmployeeAdmin(admin.ModelAdmin): ... def formfield_for_foreignkey(self, db_field, request=None, **kwargs): formfields=

Hibernate second level cache and ON DELETE CASCADE in database schema

你说的曾经没有我的故事 提交于 2019-12-05 06:55:23
Our Java application has about 100 classes mapped to a database (SQL Server or MySQL). We are using Hibernate as our ORM (with XML mapping files). We specify FOREIGN KEY constraints in our database schema. Most of our FOREIGN KEY constraints also specify ON DELETE CASCADE . We've recently started enabling Hibernate 2nd level caching (for popular entities and collections) to mitigate some performance problems. Performance has improved since we enabled the 2nd level cache. However we've also started encountering ObjectNotFoundExceptions. It seems the ObjectNotFoundExceptions are occuring because

Event Sourcing and SQL Server multiple relational tables

别等时光非礼了梦想. 提交于 2019-12-05 05:28:08
We use event sourcing with SQL Server 2016. We have total Customer Product Application, each is labelled by CustomerId and gets a single Guide line item in the event store. This is the primary identifier for write event store guids. The Product Applications comes with many different relational things, (which do not have guids but natural keys) each customer has Multiple Addresses, Accounts, Multiple purchase orders. The write event store will be mapped to a relational database tables any way we choose. In databases, we try to relate join by surrogate keys, instead of natural keys. Can the