Reputation: 3732
I've never worked with a db before, so this is all new to me. I'm working in RubyMine, Rails 3.
SQLite3::SQLException: table "projects" already exists: CREATE TABLE "projects" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "partner_id" integer, "name" varchar(255))
And in fact, if you look in the file called "20120531031320_projects.rb"
, as expected, it is trying to make a projects table:
def up
create_table :projects do |table|
table.integer :partner_id
table.string :name
end
add_index :projects, :name
end
This project was ported over from Sinatra, and maybe the db and migration files are out of sync (if that is the correct terminology). Anyway, is there way to sync things up between these migration files and the db, so that I can add a new table to the db with a new migration file?
Upvotes: 0
Views: 1209
Reputation: 3732
I solved this by putting a conditional in the migration to see if "projects" exists in the db:
def up
if (!ActiveRecord::Base.connection.tables.include?("projects"))
create_table :projects do |table|
table.integer :partner_id
table.string :name
end
end
end
Upvotes: 1