Back to Main - Articles tagged with the "Database" category:

schema.rb troubles

While watching the migrations video on the Rails site today, I noticed a feature that I was not aware of. If you edit environment.rb and un-comment the line

config.active_record.schema_format = :ruby

Rails will generate your database schema in Ruby using the db/schema.rb file, and no longer use the database system's definition language (SQL). This means that you will no longer see development_structure.sql in the db directory. However, you can still generate this file by doing a "rake db_structure_dump", if you need it.

I had no trouble generating the schema.rb, but when it came time to run my unit tests, I was getting the following message:

Phil:~/Sites/rails phil$ rake test_units

(in /Users/phil/Sites/rails)

rake aborted!

Mysql::Error: Table 'admins' already exists:

I spent a while trying to figure this one out. When you run "rake test_units" the test database is supposed to be wiped out and rebuilt using schema.rb. But this was not happening.

The solution? Delete the database manually, and recreate a new empty test database. Strange.

I do love migrations though.

Pragmatic Studio Rails Alumni
RailsConf 2006
Pragmatic Studio Advanced Rails Alumni