# Foreign\_key\_migrations plugin causing incorrect type columns to be created in test database

**URL:** <https://www.ruby-forum.com/t/foreign-key-migrations-plugin-causing-incorrect-type-columns-to-be-created-in-test-database/147760>\
**Category:** Rails\
**Created:** [September 5, 2008, 6:05am UTC](https://www.ruby-forum.com/t/foreign-key-migrations-plugin-causing-incorrect-type-columns-to-be-created-in-test-database/147760 "2008-09-05T06:05:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [September 5, 2008, 6:05am UTC](https://www.ruby-forum.com/t/foreign-key-migrations-plugin-causing-incorrect-type-columns-to-be-created-in-test-database/147760/1 "2008-09-05T06:05:05Z")

</div>

Just interested if any Rails developers who use foreign\_key\_migrations  
have come up against this or not? I’ve just raised this potential  
issue as a bug on RubyForge  
[http://rubyforge.org/tracker/index.php?func=detail&aid=21823&group\_id=1699&atid=6632](http://rubyforge.org/tracker/index.php?func=detail&aid=21823&group_id=1699&atid=6632)

…

I am discovering when I have the redhill forign\_key\_migrations & core  
in place, that when I use rails rake tasks for testing that the  
database field types created in some cases are incorrect, e.g.  
creating BIGINT as opposed to INT columns, which causes issues when it  
tries to setup the foreign keys. Note that when:

(a) create the test database vi " rake db:migrate RAILS\_ENV=‘test’ "  
=\> This is OK and there are no issues  
(b) when “rake spec” say uses things such as db:test:purge,  
db:test:clone, db:schema:load ==\> BAD COLUMNS are created.  
(c) when I delete redhillplugines (core & foreign\_key\_migrations) &  
recreate database, I can “rake spec” without an issue

More details below:  
Macintosh:myequity greg$ rails -v  
Rails 2.1.0  
Macintosh:myequity greg$ ruby -v  
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin9.3.0]  
Macintosh:myequity greg$ gem -v  
1.2.0  
Macintosh:myequity greg$

================ CASE WHERE ALL IS GOOD ================

Macintosh:myequity greg$ rake db:drop RAILS\_ENV=“test”

mysql\> desc transactions;  
±-----------------±-------------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±-----------------±-------------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| transaction\_date | date | NO | MUL | | |  
| bank\_account\_id | int(11) | NO | MUL | | |  
| category\_id | int(11) | YES | MUL | NULL | |  
| recurring\_id | int(11) | YES | MUL | NULL | |  
| amount | decimal(9,2) | NO | | | |  
| balance | decimal(9,2) | NO | | | |  
| description | varchar(255) | YES | | NULL | |  
| notes | text | YES | | NULL | |  
| created\_at | datetime | YES | | NULL | |  
| updated\_at | datetime | YES | | NULL | |  
| projection | tinyint(1) | NO | MUL | 0 | |  
±-----------------±-------------±-----±----±--------±---------------+  
12 rows in set (0.01 sec)

mysql\> desc allocations;  
±---------------±-------------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±---------------±-------------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| transaction\_id | int(11) | NO | MUL | | |  
| person\_id | int(11) | NO | MUL | | |  
| recurring\_id | int(11) | YES | MUL | NULL | |  
| amount | decimal(9,2) | YES | | NULL | |  
| amount\_percent | decimal(9,2) | YES | | NULL | |  
| created\_at | datetime | YES | | NULL | |  
| updated\_at | datetime | YES | | NULL | |  
±---------------±-------------±-----±----±--------±---------------+  
8 rows in set (0.01 sec)

========= CASE WHEN THINGS GO WRONG ===============

Macintosh:myequity greg$ rake spec --trace  
(in /Users/greg/source/myequity)  
\*\* Invoke spec (first\_time)  
\*\* Invoke db:test:prepare (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Invoke db:abort\_if\_pending\_migrations (first\_time)  
\*\* Invoke environment  
\*\* Execute db:abort\_if\_pending\_migrations  
\*\* Execute db:test:prepare  
\*\* Invoke db:test:clone (first\_time)  
\*\* Invoke db:schema:dump (first\_time)  
\*\* Invoke environment  
\*\* Execute db:schema:dump  
\*\* Invoke db:test:purge (first\_time)  
\*\* Invoke environment  
\*\* Execute db:test:purge  
\*\* Execute db:test:clone  
\*\* Invoke db:schema:load (first\_time)  
\*\* Invoke environment  
\*\* Execute db:schema:load  
rake aborted!  
Mysql::Error: #HY000Can’t create table  
‘./myequity\_test/#sql-83\_25e.frm’ (errno: 150): ALTER TABLE  
allocations ADD CONSTRAINT allocations\_ibfk\_1 FOREIGN KEY  
(transaction\_id) REFERENCES transactions (id)  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active\_record/connection\_adapters/abstract\_adapter.rb:147:in  
`log' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/connection_adapters/mysql_adapter.rb:299:in `execute’  
/Users/greg/source/myequity/vendor/plugins/redhillonrails\_core/lib/red\_hill\_consulting/core/active\_record/connection\_adapters/abstract\_adapter.rb:34:in  
`add_foreign_key' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:330:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active\_record/migration.rb:330:in  
`method_missing' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say\_with\_time’  
/opt/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/migration.rb:310:in `say\_with\_time’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active\_record/migration.rb:326:in  
`method_missing' ./db/schema.rb:182 /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/schema.rb:43:in `instance\_eval’  
/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active\_record/schema.rb:43:in  
`define_without_redhillonrails_core' /Users/greg/source/myequity/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb:19:in `define’  
./db/schema.rb:12  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active\_support/dependencies.rb:502:in  
`load' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load’  
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active\_support/dependencies.rb:354:in  
`new_constants_in' /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load’  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:226  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke’  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:271  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke’  
/opt/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/tasks/databases.rake:343  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:518:in `invoke\_prerequisites’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `send’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1183:in `each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:515:in `invoke\_prerequisites’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:507:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `synchronize’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in  
`invoke_with_call_chain' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in  
`invoke_task' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top\_level’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top\_level’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in  
`standard_exception_handling' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top\_level’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard\_exception\_handling’  
/opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run' /opt/local/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31 /opt/local/bin/rake:19:in `load’  
/opt/local/bin/rake:19  
Macintosh:myequity greg$

mysql\>  
mysql\> desc transactions;  
±-----------------±-------------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±-----------------±-------------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| transaction\_date | date | NO | MUL | | |  
| bank\_account\_id | bigint(11) | NO | MUL | | |  
| category\_id | bigint(11) | YES | MUL | NULL | |  
| recurring\_id | bigint(11) | YES | MUL | NULL | |  
| amount | decimal(9,2) | NO | | | |  
| balance | decimal(9,2) | NO | | | |  
| description | varchar(255) | YES | | NULL | |  
| notes | text | YES | | NULL | |  
| created\_at | datetime | YES | | NULL | |  
| updated\_at | datetime | YES | | NULL | |  
| projection | tinyint(1) | NO | MUL | 0 | |  
±-----------------±-------------±-----±----±--------±---------------+  
12 rows in set (0.05 sec)

mysql\> desc allocations;  
±---------------±-------------±-----±----±--------±---------------+  
| Field | Type | Null | Key | Default | Extra |  
±---------------±-------------±-----±----±--------±---------------+  
| id | int(11) | NO | PRI | NULL | auto\_increment |  
| transaction\_id | bigint(11) | NO | MUL | | |  
| person\_id | bigint(11) | NO | MUL | | |  
| recurring\_id | bigint(11) | YES | MUL | NULL | |  
| amount | decimal(9,2) | YES | | NULL | |  
| amount\_percent | decimal(9,2) | YES | | NULL | |  
| created\_at | datetime | YES | | NULL | |  
| updated\_at | datetime | YES | | NULL | |  
±---------------±-------------±-----±----±--------±---------------+  
8 rows in set (0.01 sec)

mysql\>

========= WHAT A CALL TO rake spec LOOKS LIKE WITH REDHILL PLUGINS  
REMOVED ============  
Macintosh:plugins greg$ rake spec --trace  
(in /Users/greg/source/myequity\_test1)  
\*\* Invoke spec (first\_time)  
\*\* Invoke db:test:prepare (first\_time)  
\*\* Invoke environment (first\_time)  
\*\* Execute environment  
\*\* Invoke db:abort\_if\_pending\_migrations (first\_time)  
\*\* Invoke environment  
\*\* Execute db:abort\_if\_pending\_migrations  
\*\* Execute db:test:prepare  
\*\* Invoke db:test:clone (first\_time)  
\*\* Invoke db:schema:dump (first\_time)  
\*\* Invoke environment  
\*\* Execute db:schema:dump  
\*\* Invoke db:test:purge (first\_time)  
\*\* Invoke environment  
\*\* Execute db:test:purge  
\*\* Execute db:test:clone  
\*\* Invoke db:schema:load (first\_time)  
\*\* Invoke environment  
\*\* Execute db:schema:load  
\*\* Execute spec  
Macintosh:plugins greg$
