Joe Van D. <joevandyk@…> writes:
user.save
And I get this when running rake migrate:
rake aborted!
uninitialized constant AddGenderChapterBirthdateToUsers::User
Does your User model exist?
When I remove app/models/user.rb, I get:
shiny:~/rails/vandyk damon$ rake migrate
(in /Users/damon/rails/vandyk)
== AddGenderChapterBirthdateToUsers: migrating ===============
– add_column(:users, :birth_date, :datetime,
{:default=>Sat Jan 14 18:34:45 CST 2006})
→ 0.0139s
– add_column(:users, :organization_id, :integer)
→ 0.0265s
– add_column(:users, :gender, :string, {:default=>“male”})
→ 0.0140s
rake aborted!
uninitialized constant User
So, how to fix?
Manually update the db schema version to 1 (because this was essentially
treated as a failed migration).
in the db:
UPDATE schema_info set version=1;
The other option here is to remove the 3 fields you’ve added manually
with ALTER TABLE statements.
Now, we make sure we have a model User class.
script/generate model User
We can now re-try the migration.
rake migrate VERSION=0
rake migrate
~/rails/vandyk damon$ rake migrate
(in /Users/damon/rails/vandyk)
== AddGenderChapterBirthdateToUsers: migrating =================
– add_column(:users, :birth_date, :datetime,
{:default=>Sat Jan 14 18:41:31 CST 2006})
→ 0.0138s
– add_column(:users, :organization_id, :integer)
→ 0.0264s
– add_column(:users, :gender, :string, {:default=>“male”})
→ 0.0137s
== AddGenderChapterBirthdateToUsers: migrated (0.0631s) ===========
Works.
HTH,
-damon