foreign-keys

"Parent Key Not Found" although it exists (within the TX)

I just observed a strange behaviour (of course Oracle is probably supposed to behave this way, but it didn't fit in my world view yet): I try to insert two rows into a parent and a child table, both within the same transaction: INSERT INTO V_Parent (ID, Name) VALUES (777, 'Hello World'); INSERT INTO T_Child (ParentID, Name) VALUES (777...

How can I stop Fluent NHibernate from creating foreign keys

I got a polymorphic relationship like the following example: public class A { public virtual Guid Id { get; set; } public virtual string Name { get; set; } } Class B & C contining a List of A's: public class B/C { public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual IList<A>...

MYSQL: Cannot add or update a child row: a foreign key constraint fails

I am getting the error: Cannot add or update a child row: a foreign key constraint fails (mydb/requests, CONSTRAINT requests_ibfk_5 FOREIGN KEY (fixture_id) REFERENCES fixtures (fix_id) ON UPDATE CASCADE ON DELETE CASCADE) I have the following table structure: CREATE TABLE IF NOT EXISTS `requests` ( `request_id` int(11) unsigned NOT...

How to get names of the table attributes?

Hi friends, I am working Sql Server 2005 My table name is Customer, the attributes are Orderid Customerid Customeraddress Wherein Customerid is the primary key and Orderid is the foreign key. I want to know the primary key name, foreign key name and the table name where the foreign key exists as a primary key Is there any query to...

Enable referential integrity with nHIbernate using SQlite database.

Good evening everyone, I've got a project using nHibernate (2.1.2.4000) and System.Data.SQLite (1.0.66.0). I want to enforce NHibernate to create foreign keys when it creates the database or at least use the "foreign key" keyword then I'll be able to create the triggers. I googled but I didn't find any documentation on how to do that a...

How to prevent foreign keys from messing up?

This is how my tables look: tableMembers | memberID as primary key tableAddress | addressID as primary key references memberID tableSubscription | subsID as primary key references memberID This database is for a subscription site. Basically, if a row is inserted into tableMembers, a corresponding row is inserted to each of the other...

Modify CRUD Form in web2py before sending to view

I cannot seem to find a way to modify a form that has been created via: from gluon.tools import Crud crud = Crud(globals(), db) form = crud.create(db.table_name) Since I am using foreign keys in my table, the auto-generated form only allows an integer (which represents the foreign primary key), but what I want to be able to do is ent...

web2py list reference

I am trying to get the list:reference field type to work for web2py, but for some reason I am getting an error. I am trying the example on http://web2py.com/book/default/chapter/06: db.define_table('tag',Field('name'),format='%(name)s') db.define_table('product', Field('name'), Field('tags','list:reference tag')) When I try th...

Foreign key constraint that points to one of several tables

I have a table with one column source_id whose value should be the primary key of another table, though which table it is will vary from record to record. Every record must have a value for source_table that specifies the table for the source record, and a value for source_id that specifies the row in the source table. Is there any way ...

Stackoverflows Tags system, How To

OK so now I can understand that SO's search system is primarily based around tags, the tag system they use is a very good one at that but what I want to do is replicate it for my own projects. Now I can understand how to use foreign keys and such, but I'm not exactly sure how it's been developed here, do they use 3 tables or 2 etc. How...

How to use an auto incremented primary key as a foreign key as well?

Hello This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; CREATE TABLE `child` ( `parent_id` int(11) DEFAULT NULL, `related_ids` int(11) DEFAULT NULL, KEY `parent_id` (`parent_i...

Database Design and how Foreign keys work?

If two tables have foreign keys to the same primary key of another table, does that mean that two indexes are created for those foreign keys or do they use the same index (the primary key index?) ...

SubSonic not recognizing SQLite foreign keys

I'm using SubSonic 3.0.0.3 and I can't seem to get the ActiveRecord .tt files to recognize and generate code for the foreign keys and relationships in my SQLite database. I think it generates everything else just fine, but after looking at other snippets online it looks like there should be more generated code than just single classes ...

SQL ForeignKey Column

If i use a ForeignKey in SQL, does it always have to use all the column of the table I reference from? So eg. Table1 subjectID firstname surname email Table2: car books Foreignkey(SubjectID) Can i only use one column as Foreignkey, or do I always have to get all the columns? Thanks! ...

Django ForeignKey which does not require referential integrity?

I'd like to set up a ForeignKey field in a django model which points to another table some of the time. But I want it to be okay to insert an id into this field which refers to an entry in the other table which might not be there. So if the row exists in the other table, I'd like to get all the benefits of the ForeignKey relationship. ...

SQLite: A library supporting it implements it?

I started using SQLite for my project and I found there are many libraries supporting it like Qt, pysqlite, Poco C++ etc. I also found out that previous SQLite versions didn't support foreign keys. How do the drivers know what sqlite executable to use? And how do I know they support what version of sqlite they support? Another question...

Controlling DBML EntityRef creation in DBML with multiple foreign keys

Using Linq to SQL and the autogeneration capabilities of DBML, foreign key relationships create EntityRefs in the DBML designer file. For example : private int _USStateId; private EntityRef<USState> _USState; However, if I have the need for a table with numerous FK relationships to the same table, how can i control the autogenerated...

Preventing NHibernate foreign key creation for <any> mapping

Is there a way from preventing SchemaExport from generating a foreign key constraint on mapping type? I saw a similar question about mapping, but unfortunately that wont do for . I couldn't find answer to this in NHibernate reference, but maybe someone knows a trick? I'd like to avoid removing constraint afterwards. ...

HIbernate Composite Key problem: foreign key has wrong number of columns

I am new to Hibernate and JPA, and am having difficulty setting up a composite key, as defined below: @Entity @Table(name = Entity.TABLE) @IdClass(EntityPK.class) public class MyEntity extends Entity { @CollectionOfElements @JoinTable(name="items", joinColumns = @JoinColumn(name="items")) private ...

Advantage of nullable Foreign Keys

I need to build a table for some new components that will keep track of available and used inventory. It will be something like this: CREATE TABLE components ( component_Id int NOT NULL PRIMARY KEY, workOrder_Id int FOREIGN KEY, componentSerial varchar(25) NOT NULL, foo varchar(50), bar int, information nvarchar(250) ...