Coder Social home page Coder Social logo

Comments (6)

mulderp avatar mulderp commented on June 15, 2024

Sorry. Mistake on my side.
In my Factory I include something like:

f.roles [ Role.find_by_name("foobar") ]

meaning, the call is triggered while there is no Role yet.

from factory_bot_rails.

mulderp avatar mulderp commented on June 15, 2024

for those having similar problems, have a look at the discussion here:

http://groups.google.com/group/factory_girl/browse_thread/thread/4852f1a129d72839/d1593bc8982ca651?lnk=gst&q=migration#d1593bc8982ca651

from factory_bot_rails.

jferris avatar jferris commented on June 15, 2024

Can you paste the contents of spec/factories/bar.rb?

from factory_bot_rails.

mulderp avatar mulderp commented on June 15, 2024

Factory.define :bar do |f|
f.name { "#{Faker::Company::name}-Shop-#{rand(1000).to_s}" }
f.roles do [ Role.find_by_name("Shop") ] end
end

Without the do ... end the factory would block the migration, because Role.find_by_name is not yet functional during db migration.
So, that was the mistake that I made earlier.

from factory_bot_rails.

mcfiredrill avatar mcfiredrill commented on June 15, 2024

I had this same issue. How exactly does the block fix the problem?

from factory_bot_rails.

jferris avatar jferris commented on June 15, 2024

Factory definitions are evaluated at run time. You need to make sure that any ActiveRecord models aren't directly referred to until the factory runs (rather than when the factory is defined). Otherwise, ActiveRecord will try to check the table for columns before the migrations have run.

from factory_bot_rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.