Hello,
I want to change some tablenames on my DB, but I dont want to change the
modelnames in my RailsApp. So I write down this line of code in the
model with the changed table: " set_table_name “newName” " . Also I
changed in the migrationfiles the tablenames and renamed the fixtures.
But if I now run " rake db:fixtures:load " I get an MySql Error:
My old tablename was products and sizes. Now it’s fos_products and
fos_sizes.
I write “set_table_name fos_products” and "set_table_name fos_sizes"in
my products and sizes model.
After that I renamed my fixture files from products.yml and sizes.yml to
fos_products.yml and fos_sizes.yml and I renamed in my migration files
the “create table products” statement to “create table fos_products”
etc.
Now I dropped the DB-> after that rake:db:create->rake
db:migrate->rake:db:fixtures:load
So what do you deduce from that? Your fixtures load is trying to
write to a size field, yet there is no such field, only a size_id. Do
I deduce that you have a sizes class with Product belongs_to size, and
in the fixtures you are trying to set a particular size value into the
fos_products table using the association?
If so then this does not seem to work with non-standard table names.
Whether there is a way round this I do not know. The best solution is
to chuck the fixtures in the bin and move over to Factories, probably
Machinist or Factory Girl. I prefer the former. Once you work out
how to use them you will not regret the move. If you just want to get
it going immediately then I suggest reverting to the manual method for
setting size_id, by providing a number for it and for the entries in
the sizes table. I guess there are only a couple of sizes so this
should not be a problem. A few global search/replace operations in
the fixtures should do it. Of course this paragraph started with an
‘if’ so it may not be this at all.
I do this: "I suggest reverting to the manual method for
setting size_id, by providing a number for it and for the entries in
the sizes table. "
Its not nice but it works^^
Fixtures are not nice even when they work. Maintenance is a
nightmare. As soon as you have got it all working again then move
over to Factories. The time you have wasted with this problem would
have been enough to have made the switch.
Finally just a note about the changes you made, you said you adjusted
the previous migrations so that running from scratch gave you the new
table names. A better way would just have been to add a new migration
that renamed the table.
Colin
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.