Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db:schema:load fails on second and subsequent attempts #110

Open
superchris opened this issue Apr 29, 2013 · 6 comments
Open

db:schema:load fails on second and subsequent attempts #110

superchris opened this issue Apr 29, 2013 · 6 comments

Comments

@superchris
Copy link

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.

@VanTanev
Copy link

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.

@sbleon
Copy link

sbleon commented Apr 22, 2014

This becomes even more of a problem in Rails 4.1 due to the automatic test schema maintainance.

rails/rails#14708

It would be awesome if there was a way for foreigner to hook into the process and recreate the FKs as necessary.

@matthuhiggins
Copy link
Owner

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.

@javornikolov
Copy link

Here is an example app to reproduce the problem: foreignkeysdemo

@matthuhiggins
Copy link
Owner

Very helpful @javornikolov. I will have a look at this when I have a free moment.

@sbleon
Copy link

sbleon commented Apr 28, 2014

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//issues/110#issuecomment-41519570
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants