Other rake commands work fine such as rake annotate_models.
This isn't the first time this has happened. It usually happens after
I have done a few migrations. Because I am a noob and building simple
test apps I just start a new project, copying over what I have done to
date and rake db:migrate works fine. But it isn't a satisfactory
solution.
You need to either create a new migration or roll back to the
migration before the one you are editing. If you look in your db you
will see a table called schema info. This has a single row with a
column showing the version of your migration.
If you are still developing it is fine to edit the migration, bit if
you are in production the rollback could remove data so the safest
approach is to generate a new migration.
I tried creating a new migration but once again it didn't fail but
also did not create the table.
The schema says I am on version 3 though I have tried 2 more
migrations that have not happened. If I roll back now I will roll back
to version 2 and lose a table with some test data. No big deal I
guess.
Is it your expectation that I will then be able to successfully
perform migrations once again? I'll try and see.
What does the new migration you just created say is the migration
number?
How did you create the migration? The convention is migrations are
named 003NameOfMigraton where 003 refers to the migration number.
In the migrate directory I have got to 005. The foirst 3 moigrations
worked but migration 004 and 005 did not.
I just rolled back to version=2 and then ran rake db:migrate again and
it created the table for 003 but once again did not create the tables
for 004 or 005. No errors just did not do anything for 004 and 005.
show us a listing of your db/migrate directory. If you have the same class defined in more than one migration file (typically matching the CamelCased part of the filename after then number), then your migrations go haywire. One way around this is to use very long, descriptive names for your migrations.
It didn't apply migration 004 so I tried another migration 005 and
that didn't apply wither. I rolled back to 002 and then migrated again
and it redid 003 but once again did not apply 004 or 005.
I am pretty sure there is something odd going on as in the past I have
created a new rails project and run the same migrations creating the
same tables and it works fine.
Thanks for the reply. Here is my migrate directory listing:
001_add_sessions.rb
class AddSessions (right?)
002_create_admins.rb
class CreateAdmins
003_create_users.rb
class CreateUsers
004_create_resumes.rb
class CreateResumes
005_create_cvs.rb
class CreateCvs
It didn't apply migration 004 so I tried another migration 005 and
that didn't apply wither. I rolled back to 002 and then migrated again
and it redid 003 but once again did not apply 004 or 005.
from script/console, what does this say:
puts ActiveRecord::Migrator.current_version
I'm thinking it will say 3
Of course, if any of the classes don't match the filename (more importantly, if they aren't unique), you should *make* them unique and try again.
Yep - all the class names you wrote are as they appear in the
migration file.
All the classes match the file name and are unique.
The current version in schema.rb:
ActiveRecord::Schema.define(:version => 3) do
As I say, if I now create a new project (which I am actually going to
do as I am stuffed otherwise) then all the migrations will work. It
just seems that after a while it stops applying them for no apparent
reason in an existing project.
I can absolutely confirm that I cannot get rake db:migrate to apply
more than 3 migrations. It runs with no errors but will only apply the
first 3 migrations on every new project I try. So something is clearly
preventing more than 3 migrations.
Where would I find this environment variable? I've looked in
environment.rb and development.rb and database.yml
For now I modified schema.rb from:
ActiveRecord::Schema.define(:version => 3) do
to
ActiveRecord::Schema.define(:version => 5) do
but still the migrations beyond 3 were not applied and the file gets
modified back to:
ActiveRecord::Schema.define(:version => 3) do
after I rake db:migrate
Thanks for your help - this is so frustrating and I'd love to just get
it sorted so I can get on.