I am trying to link fields between 2 of my tables but its not working.

I have a table called assets, which consists of Asset_ID and AssetType
and a table called t5_week3_shift3 which also consists of these 2 plus others.

Im not sure whether to do away with the assets table and just have both fields in the t5_week3_shift3 table, but i have recently created the t5_week3_shift3 table and i have all asset_ID's in this table which are also in assets table but i need to asset types in this table too which relate to each asset_ID.

whats the easiest way to do this, i thought i could somehow link the two tables but it doesnt work.

if i index AssetType in assets table and try to set up a relationship to assetType in t5_week3_shift3 table i get this error:
#1452 - Cannot add or update a child row: a foreign key constraint fails (`chs`.`#sql-9b0_59`, CONSTRAINT `#sql-9b0_59_ibfk_1` FOREIGN KEY (`AssetType`) REFERENCES `t5_week3_shift3` (`AssetType`))

Recommended Answers

All 2 Replies

Are you perhaps using MyIsam tables ? Another reason could be (which I encountered myself recently) that your webhost has that option turned off.

Most probably your child table contains values which are not in the master table. Check that all asset_type values of the child occur in the master.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.