Mysql::Error: #HY000Can't create table './coresales_test/#sql-1702c_b.frm' (errno: 150): ALTER TABLE agents ADD CONSTRAINT agents_ibfk_1 FOREIGN KEY (location_id) REFERENCES locations (id)It took me a bit to find the solution for this, but alas! I eventually did. To make a long story short: Rails 2.1 doesn't handle integer columns without a :limit attribute correctly by assuming a default limit of 11 and then turning that - not into int(11) - but into bigint(11). Foreign keys have to be of the same data type, though. So MySql rightly complains about it. The solution? Either use edge rails or use the monkey patch suggested in this extensive blog post about the problem. This was really quite annoying, but I'm glad that there are nice people out there providing patches and nice write-ups about such problems.
If this was useful for you, please take a minute and recommend me:
John Trupiano said...
Hey, thanks for the link back to my blog post! I'm always ecstatic when I'm able to help someone else out.