trevorhinesley
trevorhinesley

Reputation: 875

Rails migration -- rake db:status says migration is down, but database is already migrated?

I have a local PSQL database setup and am having issues getting rake db:migrate to function properly. For instance, my database has already had its high_school column name changed to high_school_name, but rake db:migrate is failing, and the status reveals this:

up     20130307043554  Adding seo tables
up     20130307185401  Create admin notes
up     20130307185402  Move admin notes to comments
up     20130308160956  Add active flad to users
up     20130308214928  Add column public to users table
up     20130325203837  Add duration to videos
up     20130326171803  Update duration of videos
down    20130410145000  Fix high school name
up     20130410145028  Add high school id to users
up     20130410161705  Convert units for stats
up     20130410164209  ********** NO FILE **********
up     20130416142844  Add column coach id to users

Why is a migration in the middle of the migration order failing/being read as "down"? Here's the error:

Migrating to AddingSeoTables (20130307043554)
Migrating to CreateAdminNotes (20130307185401)
Migrating to MoveAdminNotesToComments (20130307185402)
Migrating to AddActiveFladToUsers (20130308160956)
Migrating to AddColumnPublicToUsersTable (20130308214928)
Migrating to AddDurationToVideos (20130325203837)
Migrating to UpdateDurationOfVideos (20130326171803)
Migrating to FixHighSchoolName (20130410145000)
(0.1ms)  BEGIN
==  FixHighSchoolName: migrating ==============================================
-- rename_column(:users, :high_school, :high_school_name)
(0.4ms)  ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"
PG::Error: ERROR:  column "high_school" does not exist
: ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"
(0.1ms)  ROLLBACK
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  column "high_school" does not exist
: ALTER TABLE "users" RENAME COLUMN "high_school" TO "high_school_name"

Obviously, there is a schema issue or something. Schema is tracked via the remote branch though, so I don't know where the issue lies.

Upvotes: 2

Views: 2617

Answers (2)

azaytc
azaytc

Reputation: 63

Add resque nil to at the end of the row where column is renaming

Upvotes: 0

Michael Durrant
Michael Durrant

Reputation: 96454

I suspect that the down was not able to handle the column rename change correctly, unless just adding or removing columns.

One option you may wish to consider is actually changing the name with SQL. For instance if a migration to change high_school to high_school_name is failing and the database itself currently has high_school_name, rename that (in SQL) to high_school and then try and run the migration. This may be one option for you.

Upvotes: 3

Related Questions