db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Eaton" <sea...@gateway.net.au>
Subject working with foreign keys and null references
Date Sun, 04 May 2003 02:31:06 GMT
G'day one and all,

I'm having some issues with my schema since migrating from mysql to
postgres. In particular I'm trying to insert a record that has a foriegn key
that is not required however I keep getting the following error
"service_fk_1 referential integrity violation - key referenced from service
not found in a_contact"

The following is the table in question, as you can see I am using the single
table inheritance model, the field in question, swim_contact_id is only
required on one of the sub-classes and hence should be null most of the
time, however postgres/torque spits the dummy everytime I try to insert a
record with that field null field, I have also tried setting it to 0 as
well.

Do I just have to have dummy records in the foriegn tables at index 0 (not
really that desirable)


	<table name="service" idMethod="idbroker">
		<column name="id" primaryKey="true" required="true" inheritance="false"
type="BIGINT"/>
		<column name="service" required="true" default="null" inheritance="single"
type="VARCHAR" size="16">
			<inheritance key="EmailService" class="AEmailService"
extends="mysouthwest.swim.om.Service"/>
			<inheritance key="SwimService" class="ASwimService"
extends="mysouthwest.swim.om.Service"/>
			<inheritance key="UrlService" class="AUrlService"
extends="mysouthwest.swim.om.Service"/>
			<inheritance key="KeywordService" class="AKeywordService"
extends="mysouthwest.swim.om.Service"/>
			<inheritance key="CategoryService" class="ACategoryService"
extends="mysouthwest.swim.om.Service"/>
			<inheritance key="AdvertisingService" class="AAdvertisingService"
extends="mysouthwest.swim.om.Service"/>
			<inheritance key="MiscService" class="AMiscService"
extends="mysouthwest.swim.om.Service"/>
		</column>
		<column name="status" required="true" default="null" inheritance="false"
type="VARCHAR" size="16"/>
		<column name="date_start" required="true" inheritance="false"
type="DATE"/>
		<column name="date_renew" required="false" inheritance="false"
type="DATE"/>
		<column name="org_id" required="false" inheritance="false"
type="INTEGER"/>
		<column name="invoice_id" required="true" inheritance="false"
type="INTEGER"/>
		<column name="description_id" required="false" inheritance="false"
type="INTEGER"/>
		<column name="hits" required="true" default="0" inheritance="false"
type="INTEGER"/>
		<column name="qty" required="true" default="0" inheritance="false"
type="INTEGER"/>
		<column name="email" required="false" default="null" inheritance="false"
type="VARCHAR" size="255"/>
		<column name="url" required="false" default="null" inheritance="false"
type="VARCHAR" size="255"/>
		<column name="notification_id" required="false" default="0"
inheritance="false" type="INTEGER"/>
		<column name="swim_contact_id" required="false" default="0"
inheritance="false" type="INTEGER"/>
		<foreign-key foreignTable="a_contact">
			<reference local="swim_contact_id" foreign="contact_id"/>
		</foreign-key>
		<foreign-key foreignTable="a_notification">
			<reference local="notification_id" foreign="id"/>
		</foreign-key>
		<foreign-key foreignTable="service_description">
			<reference local="description_id" foreign="id"/>
		</foreign-key>
		<foreign-key foreignTable="a_organisation">
			<reference local="org_id" foreign="org_id"/>
		</foreign-key>
		<foreign-key foreignTable="invoice">
			<reference local="invoice_id" foreign="id"/>
		</foreign-key>
	</table>






Mime
View raw message