Jump to content

Adding A Column With Foreign Key


toreachdeepak

Recommended Posts

I have two tables as given below. I need to add a column in project_table which is INT and refers to the projecttype_table(id) field. project_table { Name Varchar(100) } projecttype_table { id INT AUTO INCREMENT NOT NULL, projecttype_name Varchar(50) }Both approaches are failing.Approach #1 =========== mysql> alter table project_table add foreign key(project_type) references projecttype_table(id); ERROR 1005 (HY000): Can't create table 'rtdb2.#sql-358a_96c' (errno: 150) Approach #2 =========== mysql> ALTER TABLE project_table TYPE=InnoDB; Query OK, 7 rows affected, 1 warning (0.02 sec) Records: 7 Duplicates: 0 Warnings: 0 mysql> alter table project_table add Foreign key (project_type) REFERENCES projecttype_table(id); ERROR 1005 (HY000): Can't create table 'rtdb2.#sql-358a_96c' (errno: 150)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...