2

I have 2 tables.

manifast

+-------------+------------------+------+-----+---------+----------------+
| Field       | Type             | Null | Key | Default | Extra          |
+-------------+------------------+------+-----+---------+----------------+
| manifast_id | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| description | text             | NO   |     | NULL    |                |
| title       | text             | NO   |     | NULL    |                |
+-------------+------------------+------+-----+---------+----------------+

day_sequence;

+-----------------+------------------+------+-----+---------+----------------+
| Field           | Type             | Null | Key | Default | Extra          |
+-----------------+------------------+------+-----+---------+----------------+
| day_sequence_id | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| day_number      | int(11)          | NO   |     | NULL    |                |
| day_start       | int(11)          | NO   |     | NULL    |                |
| manifast_id     | int(11)          | NO   |     | NULL    |                |
+-----------------+------------------+------+-----+---------+----------------+

4 rows in set (0.00 sec)

I wanna connect those two columns and use this command.

ALTER TABLE day_sequence
ADD CONSTRAINT fk_manifast
FOREIGN KEY (manifast_Id)
REFERENCES manifast(manifast_Id);

and it show this error.How can i solve?

The specified relation was unable to be created.

MySQL said: Can't create table 'projectx.#sql-3e0_4' (errno: 150)

Barmar
  • 669,327
  • 51
  • 454
  • 560
  • What table storage engine are these tables using? Could you please post the output of `SHOW CREATE TABLE manifast;` and `SHOW CREATE TABLE day_sequence;`? – Joel Cox Dec 23 '14 at 03:56
  • possible duplicate of [MySQL Creating tables with Foreign Keys giving errno: 150](http://stackoverflow.com/questions/1457305/mysql-creating-tables-with-foreign-keys-giving-errno-150) – AndySavage Dec 23 '14 at 03:57

2 Answers2

0

Manifast_id also needs to be unsigned int, looks like it is not.

Ossip
  • 1,046
  • 8
  • 19
  • cool :) had same problem myself before - need to be exactly same column type. would you mind up-voting or accept as answered? – Ossip Dec 23 '14 at 04:14
  • I really wanna vote you but I have just 1 reputation and can't do. :'( Sorry sir :3 – KaungKhant MinTun Dec 23 '14 at 04:20
  • ah, thought on own question you could? no problem, happy it worked! – Ossip Dec 23 '14 at 04:25
  • sure that does not work? (btw, it increases your reputation, too!) http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Ossip Dec 23 '14 at 19:09
0

Try fixing the other manifast id to unsigned then try doing it like this

ALTER TABLE day_sequence ADD CONSTRAINT fk_manifast FOREIGN KEY (manifast_Id) REFERENCES (manifast.manifast_Id);