I’ve never worked with a db before, so this is all new to me. I’m working in RubyMine, Rails 3.
- First, what is a migration, and why do it? Can’t I just edit a db through a database browser? Does migration retain my data, or something?
- Secondly, I inherited a project, and there are 3 files in the migration folder with names like 20120128022506_users.rb. If I just run the migrate task, I get:
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?
I solved this by putting a conditional in the migration to see if “projects” exists in the db: