foreign-keys

Why foreign key doesn't update?

↘锁芯ラ 提交于 2019-12-25 03:12:39
问题 I insert data in the column TEMP1.aa (primary key in temp1), but it doesn't import into the TEMP2.cc column (foreign key in TEMP2). Why? I thought if insert data in primary key it automatic insert into foreign key! If this true that if we insert in a primary key, foreign key must be updated? 回答1: A foreign key does not update child references, it only ensures that the value stored in the column already exists in the parent table. But MySQL supports cascading an update, by adding the ON UPDATE

Access multiple foreign fields in a Virtual Field?

ぐ巨炮叔叔 提交于 2019-12-25 03:01:38
问题 Two tables, with the relationship set up properly in Cakephp: Property (..., postcode_id ,...) and Postcode ( id , postcode, latitude, longitude). A Virtual Field created in Property beforeFind() calculates the distance between a search postcode and the record postcode. Therefore, to get the lat/long, I need to retrieve a record from the Postcode table by the foreign key in the Property record, all within the virtual field declaration. How can I do this? Multiple SELECTs nested within? Nested

fluent nhibernate foreign key with 2 columns mapping

别来无恙 提交于 2019-12-25 02:59:58
问题 I have to an existing schema and I want to map it with nhibernate. entities / table schema: post { pk_id prod_id prod_internid title } tag { pk_t_id prod_id prod_internid name } A post can have multiple tags and there is a foreign key contraint from the tag to the post table with the two columns prod_id and prod_internid. I've tried this: PostMap { // tags is a list HasMany(x => x.tags).KeyColumns.Add("prod_id", "prod_internid"); } TagMap { References(x => x.post).Columns("prod_id", "prod

SQL Server Conditional Foreign Key

拜拜、爱过 提交于 2019-12-25 02:34:27
问题 I have two tables in my SQL Server database, Foo and Bar. Table Foo is like so: +-------+ | Foo | +-------+ | Id | | Type | | Value | +-------+ The table has values like: +----+--------+-----------+ | Id | Type | Value | +----+--------+-----------+ | 1 | Status | New | | 2 | Status | Old | | 3 | Type | Car | | 4 | State | Inventory | | 5 | State | Sold | +----+--------+-----------+ The table Bar is like so: +----------+ | Bar | +----------+ | Id | | TypeId | | StatusId | | StateId | +--------

Foreign key between MySQL InnoDB tables not working…why?

末鹿安然 提交于 2019-12-25 02:27:22
问题 I have the following tables: specie (MyIsam) image (InnoDB) specie_map (InnoDB) The specie_map table should map an image to a specie, and therefore has the following columns: specie_id image_id Both are int 11, just like the id columns of the specie and image tables. I know I can't create a foreign key between specie_id and specie=>id, since the specie table is a MyIsam table. However, I would expect it to be possible to create a foreign key between image_id and image=>id. I can create that

Insert statements with primary key duplicates

痴心易碎 提交于 2019-12-25 02:21:16
问题 I did some insert statements in MySQL where some entries had the same primary Keys. I got this output in my MySQL shell: ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry '3' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry '4' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry '5' for key 'PRIMARY' ERROR 1062 (23000): Duplicate entry '6' for key 'PRIMARY' ERROR 1062 (23000):

Foreign keys have random number appended when using Hibernate's TABLE_PER_CLASS inheritance

北城以北 提交于 2019-12-25 01:44:05
问题 I currently have the following in my domain model: @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Entity abstract class Item { @ManyToOne @ForeignKey(name="FK_ITEM_ORG") @JoinColumn(name="ORG_ID") private Organization org } @Table(name = "ItemA") public class ItemA extends Item {} @Table(name = "ItemB") public class ItemA extends Item {} Hibernate's HBM2DDL creates 2 tables for this mapping: ItemA and ItemB . Both have the ORG_ID column and a foreign key to the Organization table.

Magento: a foreign key constraint fails after update 1.4 -> 1.7

半世苍凉 提交于 2019-12-25 00:21:23
问题 SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails ( my_magento/catalog_category_product_index , CONSTRAINT FK_CAT_CTGR_PRD_IDX_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID FOREIGN KEY ( category_id ) REFERENCES catalog_category_entity ( entity_id ) O) This is the error I'm getting when trying to reindex data (outputed it as it's adviced here: "There was a problem‍​​ with reindexing process." after product import ) But that solution doesn't

Django tests failing to run because they can't create table due to malformed foreign key

浪子不回头ぞ 提交于 2019-12-24 22:46:30
问题 When attempting to run my tests, I get the error in the title. It does not tell me anything remotely useful about which table has failed to be created because the raw output of the error is: django.db.utils.OperationalError: (1005, 'Can\'t create table `test_pogo`.`#sql-269_231` (errno: 150 "Foreign key constraint is incorrectly formed")') #sql-269_231 gives me absolutely no information as to where I should go and check in my models to find the error, as it is not the name of any of my models

CakePHP 3.6.11: Where clause of joined tables

痞子三分冷 提交于 2019-12-24 21:12:35
问题 I have these 3 tables: customers: customerstable services: servicestable customerservices: customerservicestable With this relation in CustomerservicesTable.php : $this->belongsTo('Customers') ->setForeignKey('customerid'); $this->belongsTo('Services') ->setForeignKey('serviceid'); In Customers edit page I want to add a table with the Services of the specific customer (and then add new, edit existing etc). So in Template\Customers\edit.ctp I have this table: <h3><?= __('Services') ?></h3>