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

Consider foreign key constraints #101

Open
qsona opened this issue Mar 4, 2016 · 2 comments
Open

Consider foreign key constraints #101

qsona opened this issue Mar 4, 2016 · 2 comments

Comments

@qsona
Copy link

qsona commented Mar 4, 2016

If table_a has table_b_id column, and the foreign key constraint exists, seed_fu tries to insert initial table_a data and fails because of the constraint.

As far as I know, seed_fu reads files in alphabetical order of filenames.
So I can change the filenames into
db/fixtures/01_table_b.rb and db/fixtures/02_table_a.rb to fix it, but I think it's better if we need not do it.
Is there any solution? Thanks.

takegue added a commit to takegue/group-manager that referenced this issue Jul 7, 2016
    - ファイル名によって取り込む順番を決定させる. (参考)(mbleigh/seed-fu#101)
@stuarthannig
Copy link

stuarthannig commented Aug 9, 2017

Yes, foreign key constraint consideration would be nice. Working around it myself.

@eliotsykes
Copy link

Disabling referential integrity during seeding is a workaround for some situations, but note postgresql (and I'm assuming other dbs) will not validate the constraints afterward, so you can end up with orphaned foreign keys:

ActiveRecord::Base.connection.disable_referential_integrity do
  SeedFu.seed
end

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

3 participants