School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,396 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,617 people online right now. Registration is fast and FREE... Join Now!




Foreign key problem

 

Foreign key problem

livium

18 Jun, 2009 - 05:41 AM
Post #1

D.I.C Regular
***

Joined: 21 Dec, 2008
Posts: 294


My Contributions
I'm trying to set a foreign key to a table by using the alter command (in wamp) in this way:


CODE

ALTER TABLE projects
ADD FOREIGN KEY (id_project) REFERENCES users_projects(id_project);


And i get this error #1005 - "Can't create table 'free_code.#sql-45c_250' (errno: 150)"

The id_project form table projects is a primary key and it is autoincremented. The field id_project from users_projects has the same definition (it is indexed) with the difference that it is not autoincremented.

Both tables are InnoDB.

Where i'm I going wrong? I don't understand what is the problem.

Thanks!


User is offlineProfile CardPM
+Quote Post


ellisgl

RE: Foreign Key Problem

22 Jun, 2009 - 01:57 PM
Post #2

D.I.C Head
Group Icon

Joined: 10 Nov, 2007
Posts: 118



Thanked: 3 times
Dream Kudos: 25
My Contributions
A couple things could be wrong:
1.) Make sure the types match
2.) Make sure that a key/pk doesn't exist with the same name.
3.) And make sure you are linking to a key

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 10:04PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month