Rails model validators break earlier migrations -


i have sequence of migrations in rails app includes following steps:

  1. create basic version of 'user' model
  2. create instance of model - there needs @ least 1 initial user in system can log in , start using it
  3. update 'user' model add new field / column.

now i'm using "validates_inclusion_of" on new field/column. worked fine on initial development machine, had database these migrations applied. however, if go fresh machine , run migrations, step 2 fails, because validates_inclusion_of fails, because field migration 3 hasn't been added model class yet.

as workaround, can comment out "validates_..." line, run migrations, , uncomment it, that's not nice.

better re-order migrations user creation (step 2) comes last, after columns have been added.

i'm rails newbie though, thought i'd ask preferred way handle situation :)

the easiest way avoid issue use rake db:schema:load on second machine, instead of db:migrate. d:s:l uses schema.rb load current version of schema, opposed migrating form scratch.

if run issue when deploying production machine (where preserving data important), you'll have consolidate migrations single file without conflicts.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -