foreign-key-relationship

“Invalid Index n for this SqlParameterCollection with Count=n” OR “foreign key cannot be null”

血红的双手。 提交于 2019-12-18 18:36:42
问题 I have been successfully using NHibernate for quite some time now and have been able to solve a lot of pitfalls with an application that I developed with it and that is running in production. The recent hurdle really has me scratching my head, though. Recently I had to expand the class library with some new classes that are nested as children to some already existing classes. I just copied the same model for aggregate mapping that I already was successfully using, but this time it does not

Need to create a foreign key when creating a table on Rails?

我是研究僧i 提交于 2019-12-18 15:50:45
问题 i'm starting now on Rails, i looked in the forum, but i didn't find anything that could solve my problem. Here it goes, I have a Category table, and it has only name for a column (there is no repetition in categories) so i would like name to be the primary key, then i have a Product table that has name, main_photo, description and i would like to say that a product only has a category, do i need to add a column named category as a foreign key in products? A Category is suposed to have many

Can SQLAlchemy automatically create relationships from a database schema?

萝らか妹 提交于 2019-12-18 13:10:33
问题 Starting from an existing (SQLite) database with foreign keys, can SQLAlchemy automatically build relationships? SQLAlchemy classes are automatically created via __table_args__ = {'autoload': True} . The goal would be to easily access data from related tables without having to add all the relationships one by one by hand (i.e. without using sqlalchemy.orm.relationship() and sqlalchemy.orm.backref ). 回答1: [Update] As of SQLAlchemy 0.9.1 there is Automap extension for doing that. For SQLAlchemy

SQLite Foreign Key

蓝咒 提交于 2019-12-18 10:35:47
问题 I'm following the instructions from the SQLite documentation at http://www.sqlite.org/foreignkeys.html however my attempt to add a foreign key is failing. Here are my create statements: CREATE TABLE checklist ( _id INTEGER PRIMARY KEY AUTOINCREMENT, checklist_title TEXT, description TEXT, created_on INTEGER, modified_on INTEGER ); CREATE TABLE item ( _id INTEGER PRIMARY KEY AUTOINCREMENT, FOREIGN KEY(checklist_id) REFERENCES checklist(_id), item_text TEXT, item_hint TEXT, item_order INTEGER,

Reference to composite primary key in Access 2007

倖福魔咒の 提交于 2019-12-18 08:50:30
问题 I have looked around and found some questions similar but they were for SQL Server instead. Here is a small database structured I have create just to show you the relationships I want to model. Basically it's quite simple, each year has 12 periods and an instance of period-year cannot occur twice (period 9 year 2012 cannot occur more than once ever). So I thought that the best way to model this would be to have a table period with only one field with values from 1-12, a table year following

unable to drop the foreign key

别来无恙 提交于 2019-12-18 01:42:32
问题 I would like to drop the foreign key in my table but been into this error message mysql> alter table customers drop foreign key customerid; ERROR 1025 (HY000): Error on rename of '.\products\customers' to '.\products\#sql2-7ec-a3' (errno: 152) mysql> 回答1: To avoid getting this error while trying to drop a foreign key, use the constraint name rather than the column name of the foreign key. When I tried mysql> ALTER TABLE mytable DROP PRIMARY KEY; I got error as ERROR 1025 (HY000): Error on

How to disable Constraints for all the tables and enable it?

跟風遠走 提交于 2019-12-17 22:33:59
问题 I have 60 tables. I want to drop 10 tables where these 10 tables are Constraints(PK,FK) to other 20 tables. While dropping these 10 tables, I need to truncate or delete data from the other 20 tables. Finally I want to disable all 60 table Constraints(FK,PK) and then enable all 60 table constraints after I am done with my work of adding/dropping tables. Is this possible? When I drop a table it is asking for FK. When I truncate those FK dependencies it also is still showing the same. I don't

One to Many MySQL [duplicate]

久未见 提交于 2019-12-17 16:37:50
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: MySQL Relationships I am trying to create a one to many relationship in MySQL with foreign keys. Two tables, user and location . Each user can have many location s, but each location can have only one user . How do I configure this? I am using HeidiSQL if that helps, though I can input code as well. 回答1: MySQL does not know, nor does it need to know if a relationship is 1-1, or 1-many. No SQL supports many

Proper database model for a user feedback system (an interesting case)

元气小坏坏 提交于 2019-12-17 09:57:57
问题 I am developing an application using PHP and Yii Framework. I've been thinking about the most suitable database structure for the given functionality and here's what I've come up with. Yet I'm not 100% positive that's how it should be done so I've decided to ask the community. App Description: Registered users may participate in an event. Every event can have an unlimited number of users, called "participants of the event"). Once the event is over, every participant can leave a feedback about

Defining multiple Foreign Key for the Same table in Entity Framework Code First

拟墨画扇 提交于 2019-12-17 06:27:32
问题 I have two entities in my MVC application and I populated the database with Entity Framework 6 Code First approach. There are two city id in the Student entity; one of them for BirthCity, the other for WorkingCity. When I define the foreign keys as above an extra column is created named City_ID in the Student table after migration. Id there a mistake or how to define these FKs? Thanks in advance. Student: public class Student { public int ID { get; set; } public string Name { get; set; }