Admdebian
Admdebian

Reputation: 660

Django Mysql Migration Error 150 with FOREIGN KEY

I need help debugging a migration.

I tried to execute each query step by step to found where django migration stops.

This query fails:

mysql> ALTER TABLE `elezioniAgendaCore_comments` ADD CONSTRAINT `elezioniAgendaCore_comments_uid_id_670175fa07fa7b47_fk_user_uid` FOREIGN KEY (`uid_id`) REFERENCES `user` (`uid`);

With Error:

ERROR 1005 (HY000): Can't create table 'activedoc.#sql-3f7_2b' (errno: 150)

I have tow tables.

TABLE user:

mysql> show columns from user;
+-------------------+--------------+------+-----+---------+----------------+
| Field             | Type         | Null | Key | Default | Extra          |
+-------------------+--------------+------+-----+---------+----------------+
| uid               | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| name              | varchar(50)  | YES  | MUL | NULL    |                |
| surname           | varchar(50)  | YES  | MUL | NULL    |                |
| email             | varchar(100) | YES  | MUL | NULL    |                |
+-------------------+--------------+------+-----+---------+----------------+

TABLE elezioniAgendaComments:

mysql> show columns from elezioniAgendaCore_comments;
+------------------+--------------+------+-----+---------+----------------+
| Field            | Type         | Null | Key | Default | Extra          |
+------------------+--------------+------+-----+---------+----------------+
| id               | int(11)      | NO   | PRI | NULL    | auto_increment |
| signature        | varchar(255) | NO   |     | NULL    |                |
| message          | longtext     | NO   |     | NULL    |                |
| created          | datetime     | NO   |     | NULL    |                |
| published        | tinyint(1)   | NO   |     | NULL    |                |
| adempimento_id   | int(11)      | NO   | MUL | NULL    |                |
| parentComment_id | int(11)      | YES  | MUL | NULL    |                |
| uid_id           | bigint(20)   | NO   |     | NULL    |                |
+------------------+--------------+------+-----+---------+----------------+

Upvotes: 1

Views: 99

Answers (1)

Admdebian
Admdebian

Reputation: 660

I found one table was created with MyISAM engine:

SHOW CREATE TABLE user;

[...]

) ENGINE=MyISAM AUTO_INCREMENT=307 DEFAULT CHARSET=latin1 |

The other table:

mysql> SHOW CREATE TABLE elezioniAgendaCore_comments;

[...]

) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

Then I migrated to InnoDB both tables. No errors this time.

Upvotes: 1

Related Questions