Question

I am developing a Ruby on Rails application, and using the foreigner plugin to set up foreign key constraints in the migrations for example like this.

add_foreign_key(:notifications, :invitations, :dependent => :delete)

However, when I run the migration with

rake db:migrate

It runs, but my schema.rb file remains unchanged. Shouldn't the changes be reflected there for setup on another database?

Was it helpful?

Solution 2

So, thanks to ctilly79 I found the answer. For some reason I thought that since I was using SQLite it would still make the foreign keys in Schema.rb for use in production. This is not the case. You have to be using something that supports foreign keys such as MySQL for it to work.

OTHER TIPS

If you are using mysql you can you test to see if it actually created the foreign key? I agree that according to the schema.rb documentation, if you plan to move the application to another system you should run rake db:schema:load. So if the information is not there it obviously won't work. You would be forced to run through all of your migrations. I have been reading through the foreigner gem source code and it seems that the gem should inject statements into your schema. The link to the code that I think does this is:

https://github.com/matthuhiggins/foreigner/blob/master/lib/foreigner/schema_dumper.rb

The only thing i can tell you to try is generate the schema.rb from scratch, and see if the schema fully populates. If not it seems you will be force to run your migrations when you move to another system. You can also post your question on the github project page. Developers are usually pretty quick to answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top