Non standard primary keys in Rails test databases
In one of my models I use a non standard primary which is handled in the migration file lik开发者_高级运维e this:
create_table item_similarities, :id => false do |t|
and
execute "ALTER TABLE item_similarities ADD constraint pk_item_similarities " +
"PRIMARY KEY (item_id_1, item_id_2)"
Now, when I run rake test
the schema is copied into the test database but without setting the primary key (item_id_1, item_id_2) in the test database.
Could anyone please help how this can be achieved?
Rails doesn't have a lot of support for composite primary keys.
Try dumping the sql structure of your database like this:
rake db:structure:dump
It should create a file like db/development_structure.sql
Then do this to load that file into your test database:
rake db:test:clone_structure
Rails dumps it schema information into db/schema.rb. Check that file, but your own SQL will probably not be there. You can set it to dump sql, but I don't know if your own SQL will be included:
ActiveRecord::Base.schema_format = :sql
精彩评论