开发者

How to recreate test fixtures based on development database schema

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 dupl开发者_StackOverflow中文版icate 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?


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


I completely agree that you should not change the database without using migrations, but recreating the fixtures is still a problem that people bump into from time to time. The best solution I have found is here:

http://snippets.dzone.com/posts/show/2525

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜