Rails 3 test database issues

I am having a problem using the test database in Rails 3. It apparently has kept track of aspects of the database that I deleted completely from my migrations at some point. I don't always use the 'down' part of a migration and sometimes just recreate the whole database. I did rake db:migrate:reset and rake db:test:prepare, but when I run my test it is trying to access tables that are not in the test at all and fields that are not in that table.

test_attr_merge(UserSectionTest): ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'conversion_dir_id' in 'field list': INSERT INTO `conversions` (`file_name`, `conversion_dir_id`, ` created_at`, `updated_at`, `id`) VALUES ('MyString', 1, '2011-07-25 13:32:52', ' 2011-07-25 13:32:52', 980190962)     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con nection_adapters/abstract_adapter.rb:202:in `rescue in log'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con nection_adapters/abstract_adapter.rb:194:in `log'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con nection_adapters/mysql_adapter.rb:289:in `execute'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con nection_adapters/abstract/database_statements.rb:239:in `insert_fixture'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:646:in `block in insert_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:582:in `each'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:582:in `insert_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:526:in `block (4 levels) in create_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:526:in `each'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:526:in `block (3 levels) in create_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con nection_adapters/abstract/database_statements.rb:139:in `transaction'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:524:in `block (2 levels) in create_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con nection_adapters/mysql_adapter.rb:228:in `disable_referential_integrity'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:515:in `block in create_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/ active_support/b enchmarkable.rb:55:in `silence'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:514:in `create_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:973:in `load_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix tures.rb:938:in `setup_fixtures'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/ active_support/c allbacks.rb:414:in `_run_setup_callbacks'     C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/ active_support/t esting/setup_and_teardown.rb:34:in `run'

2 tests, 0 assertions, 0 failures, 2 errors, 0 skips

Test run options: --seed 35707

did you run your migrations for test environment as well?

RAILS_ENV=test rake db:migrate

?

Does rake db:test:prepare do this? I'm not sure from looking at the Guide.

**Leigh

No, I hadn't tried that, but I just did the following below along with that and it is trying to access a table that maybe I had at one time 'ingredients', but no longer have in my schema or migrations. I guess I might like to completely destroy my databases and start over. Not sure the easiest way to do that ..

C:\Users\Laurence\pdf-parse\univ-parse\web>rake db:reset (in C:/Users/Laurence/pdf-parse/univ-parse/web) -- create_table("alt_values", {:force=>true})    -> 0.1700s -- create_table("attribute_values", {:force=>true})    -> 0.1200s -- create_table("conversion_directories", {:force=>true})    -> 0.0810s -- create_table("conversions", {:force=>true})    -> 0.0760s -- create_table("msds_attrs", {:force=>true})    -> 0.0990s -- create_table("msds_directories", {:force=>true})    -> 0.1200s -- create_table("msds_files", {:force=>true})    -> 0.1090s -- create_table("msds_ingredients", {:force=>true})    -> 0.1380s -- create_table("parsed_sections", {:force=>true})    -> 0.1250s -- create_table("sections", {:force=>true})    -> 0.1420s -- create_table("user_sections", {:force=>true})    -> 0.1760s -- initialize_schema_migrations_table()    -> 0.4600s -- assume_migrated_upto_version(20110720211337, "db/migrate")    -> 0.6870s

C:\Users\Laurence\pdf-parse\univ-parse\web>rake db:migrate (in C:/Users/Laurence/pdf-parse/univ-parse/web)

C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web>rake db:migrate RAILS_ENV=test (in C:/Users/Laurence/pdf-parse/univ-parse/web)

C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web> C:\Users\Laurence\pdf-parse\univ-parse\web>ruby -Itest test/unit/ user_section_te st.rb Loaded suite test/unit/user_section_test Started EE Finished in 3.044175 seconds.

) Error: t_attr_merge(UserSectionTest): iveRecord::StatementInvalid: Mysql::Error: Table 'univ_parse_test.ingredients oesn't exist: DELETE FROM `ingredients` C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract_adapter.rb:202:in `rescue in log' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract_adapter.rb:194:in `log' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/mysql_adapter.rb:289:in `execute' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract/database_statements.rb:269:in `update_sql' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/mysql_adapter.rb:306:in `update_sql' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract/database_statements.rb:274:in `delete_sql' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract/database_statements.rb:54:in `delete' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract/query_cache.rb:16:in `delete' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:563:in `delete_existing_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:525:in `block (4 levels) in create_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:525:in `each' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:525:in `block (3 levels) in create_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/abstract/database_statements.rb:139:in `transaction' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:524:in `block (2 levels) in create_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/con tion_adapters/mysql_adapter.rb:228:in `disable_referential_integrity' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:515:in `block in create_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/ active_support/b hmarkable.rb:55:in `silence' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:514:in `create_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:973:in `load_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.3/lib/ active_record/fix es.rb:938:in `setup_fixtures' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/ active_support/c backs.rb:414:in `_run_setup_callbacks' C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.3/lib/ active_support/t ing/setup_and_teardown.rb:34:in `run'

rake db:test:prepare loads your schema.rb (or dbstructure.sql) into your test database. I don't think that's the problem.

Looking at the stack trace, I would guess that you still have some fixture files for tables that you have deleted.

Sarah