foreigner
foreigner copied to clipboard
db:schema:load fails on second and subsequent attempts
Trying to run db:schema:load runs the first time, but on subsequent tries it fails trying to drop any tables that have foreign keys defined on them. This is happening in both postgres and sqlserver.
I ran into a similar problem - basically when dealing with FKs you need a SET FOREIGN_KEY_CHECKS = 0; before everything and SET FOREIGN_KEY_CHECKS = 1; at the end (for mysql >= 4.1.x)
I don't know if this is the best way to go about it, but I just use:
ActiveRecord::Base.connection.execute("SET FOREIGN_KEY_CHECKS = 0;");
Mind you, this doesn't work in PostgreSQL.
This becomes even more of a problem in Rails 4.1 due to the automatic test schema maintainance.
https://github.com/rails/rails/issues/14708
It would be awesome if there was a way for foreigner to hook into the process and recreate the FKs as necessary.
I'm on Rails 4.1 and can run db:schema:load repeatedly for my Rails 4.1 app. I need an example app to reproduce.
Here is an example app to reproduce the problem: foreignkeysdemo
Very helpful @javornikolov. I will have a look at this when I have a free moment.
Thanks for setting that up, @javornikolov https://github.com/javornikolov !
On Sun, Apr 27, 2014 at 11:03 PM, Matthew Higgins [email protected]:
Very helpful @javornikolov https://github.com/javornikolov. I will have a look at this when I have a free moment.
Reply to this email directly or view it on GitHubhttps://github.com/matthuhiggins/foreigner/issues/110#issuecomment-41519570 .