Referential integrity only disabled on primary database when fixtures are loaded
Closed this issue · 2 comments
Fixtures are not loaded when I am using fixtures :all in my test helper file. I am running a project with a legacy DB and a rails generated db. I don't have migrations for the legacy DB but instead relying on running db:setup to generate the schema for the legacy DB.
I am using multiverse version 0.2.1 with rails 5.1.4 and mysql 0.4.10
It seems on running rails test I get an error related to the order of the data, implying that referential integrity has not been disabled, below is the error:
ActiveRecord::InvalidForeignKey: Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails
The below stack trace was given:
/Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `_query' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/mysql2-0.4.10/lib/mysql2/client.rb:120:in `block in query' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `handle_interrupt' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/mysql2-0.4.10/lib/mysql2/client.rb:119:in `query' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:215:in `block (2 levels) in execute' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:46:in `block in permit_concurrent_loads' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:185:in `yield_shares' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:45:in `permit_concurrent_loads' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:214:in `block in execute' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:612:in `block (2 levels) in log' /Users/ramywafa/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:611:in `block in log' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:603:in `log' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:213:in `execute' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/mysql/database_statements.rb:26:in `execute' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:329:in `insert_fixture' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:553:in `block (5 levels) in create_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:552:in `each' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:552:in `block (4 levels) in create_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:551:in `each' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:551:in `block (3 levels) in create_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:540:in `each' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:540:in `block (2 levels) in create_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction' /Users/ramywafa/.rvm/rubies/ruby-2.3.7/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:538:in `block in create_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:184:in `disable_referential_integrity' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:522:in `create_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:1029:in `load_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:965:in `setup_fixtures' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/activerecord-5.1.4/lib/active_record/fixtures.rb:851:in `before_setup' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:105:in `block (3 levels) in run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:204:in `capture_exceptions' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:104:in `block (2 levels) in run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:255:in `time_it' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:103:in `block in run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:350:in `on_signal' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:275:in `with_info_handler' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest/test.rb:102:in `run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:839:in `run_one_method' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:324:in `run_one_method' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:311:in `block (2 levels) in run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:310:in `each' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:310:in `block in run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:350:in `on_signal' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:337:in `with_info_handler' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:309:in `run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:159:in `block in __run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:159:in `map' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:159:in `__run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:136:in `run' /Users/ramywafa/.rvm/gems/ruby-2.3.7@qualgs/gems/minitest-5.10.3/lib/minitest.rb:63:in `block in autorun'
Do I have to load fixtures by hand and order their insertions?
Hey @ramywafa, it looks like disable_referential_integrity
is only called on the primary database when fixtures are loaded. Happy to review a PR if you want to take a shot at fixing it.
Added a note in the readme about this limitation.