views:

74

answers:

1

The situation: I used generate scaffold to set up my objects in a new Rails project. Besides doing some migrations, I also directly edited the MySQL tables by adding and renaming columns etc. Now I can't get tests to run because the automatically-generated fixtures do not correspond to the database schema. Perhaps they're based on the original definitions plus migrations, and my migrations to not completely describe the new structure.

I discovered I could use "rake db:test:clone_structure" to duplicate the tables in the test database (db:test:prepare apparently creates them from the migrations?), but I can't figure out how to get the fixtures created from the development schema rather than from the migrations (or whatever is happening).

I got as far as seeing that there is a Fixtures.create_fixtures method, but where would I put it and how would I use it to regenerate all my fixtures?

+1  A: 

When working with rails you never do this - "directly edited the MySQL tables by adding and renaming columns" You create migrations

http://guides.rubyonrails.org/migrations.html

abdollar
Does everyone agree with this? I'm just learning. The site you refer to says "You could edit fragments of SQL by hand but you would then be responsible for telling other developers ... [and] keep track of which changes need to be run against the production machines next time you deploy." Since I'm just getting started on this personal project, it didn't seem that running a migration every time I wanted to add or change a column name was that important. You're implying, though, that migrations are actually *necessary* for any change. Anyway, there must be a way to create the fixtures.
Mike Blyth
Migrations are a major part of rails. They allow you to stay agile and avoid the need to tell other engineers which changes you have made. Try your best to use migrations - its the rails way. Fixtures can be really annoying. Change your fixtures and expect everyone to run migrations and use rake db:fixtures:load- if they need to seed the database to get going
abdollar
I agree with abdollar. Weird things will happen with ActiveRecord if you don't use migrations
Mauricio