foreign-key-relationship

JPA EclipseLink oneToMany Derived Ids Fail

允我心安 提交于 2020-01-07 07:40:06
问题 Hello I'm trying to make an example of persistence of a OneToMany relationship in which I get the following error: Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [entitys.OrderItemPK] and those of the entity bean class [class entitys.OrderItem] must correspond and their types must be the same. Also, ensure that you have specified ID elements for the corresponding attributes in XML and/or an @Id on

How to select an object through a foreign key

…衆ロ難τιáo~ 提交于 2020-01-06 08:13:34
问题 If I have a table with a primary key (AccLinkID) and a foreign key (aspnet_Users UserID), how can I select the object that the foreign key points to using Linq to Entities. User myUser = _myDB.AccLinkSet.Where(user => user.LinkID == linkId).FirstOrDefault().aspnet_Users; did not work... anyone have any ideas? 回答1: Try this: User myUser = _myDB.AccLinkSet.Include("aspnet_Users") .Where(user => user.LinkID == linkId).FirstOrDefault().aspnet_Users; 回答2: Although you can solve this with Include,

“SQLSTATE[23000]: Integrity constraint violation” with valid constraint

血红的双手。 提交于 2020-01-05 04:42:26
问题 I'm using Symfony 2 with Doctrine. I have 4 classes: Country, District, County and Local. District has a foreign key of Country; County has a foreign of District; Local has a foreign key of District. The problem is that when inserting a County (using data fixtures), I get the error SQLSTATE[23000]: Integrity constraint violation: I dumped the SQL to create the tables and constraints and got this: CREATE TABLE Country (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, insertedAt

SQLite Foreign Key Constraint Failed (code 787)

寵の児 提交于 2020-01-02 00:52:35
问题 I ran into the Foreign Key Constraint Failed (code 787) error when I tried to upgrade my database. The only change I did was try to add a 4th entry to my InsertStatus . I looked around and I read that using ON DELETE CASCADE should solve my problem so I tried placing it at all my FK references and tried again but still the same problem. Logcat points to my onUpgrade and all the DROP TABLES in it ( i tried removing it one at a time to see which ones were bad and apparently all of them were ).

How to find all foreign keys?

痴心易碎 提交于 2020-01-01 16:48:30
问题 I'd like to find all referencing tables in my db that have a foreign key that points to a specific referenced table. Is there a query that I can run to do this? Not sure if the question is confusing. Let me know if it is and I can try to explain it in more detail. 回答1: The following query or Modification tehreof will do - in Sql server You can also supply catalog and schema info select tab1.TABLE_NAME from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS as ref inner join INFORMATION_SCHEMA.TABLE

Entity Framework (Database-First) multiple relations to same table naming conventions control

喜夏-厌秋 提交于 2020-01-01 07:33:06
问题 Let's suppose that we have this situation: Tables in database: Country (id, country_name), Person (id, login), CountryManager (id_country, id_person), CountryStakeholder (id_country, id_person) If we had to create the model from the database, using Entity Framework Database-First, in VS we'd have a class like this: class Country { int id; string country_name; virtual ICollection<Person> Person1; // Navigation Properties virtual ICollection<Person> Person2; // ---------||---------- } I've

How to use trigger in MySql to make foreign key

送分小仙女□ 提交于 2019-12-31 07:26:52
问题 I want to use trigger to make foreign key in MySql. I have the following tables: 1) 'content' table: teacher_id varchar(20) sub_id varchar(20) path varchar(100) file_name varchar(100) 2) 'teacher' table: teacher_id varchar(20) teacher_name varchar(45) and I am using the following code for trigger(delimiter //): CREATE TRIGGER fk_content_teacher_temp BEFORE INSERT ON `content` FOR EACH ROW BEGIN DECLARE has_row TINYINT; SET has_row = 0; SELECT 1 INTO has_row FROM `teacher` INNER JOIN `content`

1:1 relationship problems with EF Model First

眉间皱痕 提交于 2019-12-31 03:51:07
问题 I'm trying to develop an application as Model-First with EF. I tried everything to accomplish a table-splitting pattern and a 1:1 relationship but looks like EF just doesn't let me. Assuming I do use Model-First - is there a way to put a 1:1 relationship without messing with the generated files and EF giving that annoying: Multiplicity is not valid in Role 'Blablalah' in relationship 'Blabalbala'. Because the Dependent Role properties are not the key properties, the upper bound of the

Advice on design relations between tables

大憨熊 提交于 2019-12-30 12:54:09
问题 I have information about music albums that I want to organise in RDBMS tables with relations between them. I have the following info for each album: artist, album name, year, label, genre, style, rating. So far I think to make 4 tables - artists, albums (name, year, label, rating), genre1 and genre2 (each genre with its styles). On the diagram it looks as follows: But don't know yet how can I establish a connection between albums and the other three tables? I.e., when I will run a query

SQLAlchemy: Relation table with composite primary key

我们两清 提交于 2019-12-30 02:13:26
问题 I have a set of tables that look like: workflows = Table('workflows', Base.metadata, Column('id', Integer, primary_key=True), ) actions = Table('actions', Base.metadata, Column('name', String, primary_key=True), Column('workflow_id', Integer, ForeignKey(workflows.c.id), primary_key=True), ) action_dependencies = Table('action_dependencies', Base.metadata, Column('workflow_id', Integer, ForeignKey(workflows.c.id), primary_key=True), Column('parent_action', String, ForeignKey(actions.c.name),