There is already an object named 'schema_migrations' in the database

I’ve created a table in a SQL Server database using a migration,
successfully.
I’ve tried to change the name of a column in the table and got the
error message above when running ‘rake db:migrate’.
Previously I have developed using MySQL and Sqlite and migrations have
worked successfully. This is an error I have not seen before.
Has anybody seen this and worked around it?

thnx
Martin

On Thu, Jan 8, 2009 at 8:03 AM, Martin H.
[email protected] wrote:

I’ve created a table in a SQL Server database using a migration,
successfully.
I’ve tried to change the name of a column in the table and got the
error message above when running ‘rake db:migrate’.

It sounds like you edited an existing migration – if so, don’t :slight_smile:

Create a new migration to change the column, or drop the entire DB
and start from scratch.

HTH,

Hassan S. ------------------------ [email protected]

Hassan,
Thanks for the reply.
No, I didn’t edit an existing migration - I created a new one for the
rename.

I understand what you are saying about dropping the table (not the
entire db surely :-0). While that would work, I wouldn’t get to
understand what the problem is!!

Martin

On Jan 8, 4:18 pm, “Hassan S.” [email protected]

Yes, I agree that the second migration seems to be trying to re-create
the schema table.

The database is a legacy SQL Server db with over 100 tables already in
existence.
I’ve noticed that db/schema.rb contains no information re the table
that was built, hence rake trying to re-create the schema_migrations
table.
The first migration created a searches table:
class CreateSearches < ActiveRecord::Migration
def self.up
create_table :searches do |t|
t.date :start
t.date :end
t.integer :team_id
t.integer :match_id
t.integer :innings_id
t.integer :over_id
t.integer :ball_id
t.integer :match_session_id
t.integer :bowler_id
t.integer :delivery_type_id
t.integer :extra_type_id
t.integer :appeal_id
t.integer :shot_type_id
t.integer :runs_id
t.integer :batter_id
t.integer :umpire_id
t.integer :validity_id
t.integer :decison_id
t.integer :height_id
t.integer :extra_runs_id
t.timestamps
end
end

def self.down
drop_table :searches
end
end
and the second migration tried to rename one of the columns:

class RenameTeamId < ActiveRecord::Migration
def self.up
rename_column :searches, :team_id, :home_team_id
end

def self.down
rename_column :searches, :home_team_id, :team_id
end
end

Dropping the whole DB is really not an option.
Martin

On Jan 8, 4:41 pm, “Hassan S.” [email protected]

On Thu, Jan 8, 2009 at 8:36 AM, Martin H.
[email protected] wrote:

No, I didn’t edit an existing migration - I created a new one for the
rename.

It sounds like your second migration is trying to create the schema
table
which already exists.

Maybe you could post your migrations, or at least the failing one?

I understand what you are saying about dropping the table (not the
entire db surely :-0).

Yes, the whole DB – if you’re wanting to fix a bad migration and run
it all from the beginning. That’s not a bad thing early in a project.


Hassan S. ------------------------ [email protected]

On Thu, Jan 8, 2009 at 9:07 AM, Martin H.
[email protected] wrote:

The database is a legacy SQL Server db with over 100 tables already in
existence.
I’ve noticed that db/schema.rb contains no information re the table
that was built, hence rake trying to re-create the schema_migrations
table.

The first migration created a searches table:

And that was created with no errors? I assume you’ve looked in the
SQL Server error log(s)?

and the second migration tried to rename one of the columns:

So what does schema_migrations contain at this point?

Dropping the whole DB is really not an option.

Got it. But if I were you, I’d create a new temporary rails projects,
just
using sqlite3,. and try running your migrations there as a test. If they
work there, then there’s something peculiar to your original config.

Caveat: I know zero about MS SQL Server so…


Hassan S. ------------------------ [email protected]