Questions tagged [rails-migrations]

Rails migrations are used to track and apply database alterations in a reversible manner.

Migrations are a way to alter your database in a reversible manner using (usually) Ruby classes and objects rather than raw SQL. Rails also keeps track of which migrations have run so a simple

$ rake db:migrate

is all that is needed to bring your database up to date even if different people have made different changes. The migrations also maintain your db/schema.rb file.

Links:

1033 questions
0
votes
1 answer

Add New Pages to CMS in Rails

I'm more-so looking for a best practice. I'm working in a team on a rather large project. I'm doing the server side coding and someone else is doing the designing. We decided to do an in-house style CMS so someone else can make some changes to…
0
votes
1 answer

Rollback and change or create a new migration

I am just curious, Suppose I create this migration: def change create_table :pages do |t| t.string :title t.text :content t.timestamps end end and then I run the migration. Now after a couple of hours I remember that I should have…
Omid Kamangar
  • 5,768
  • 9
  • 40
  • 69
0
votes
1 answer

Problems using add_foreign_key in gem migration

I found the answer here unhelpful: Rails 3 Add Foreign Key in Migration Problems Implementing a namedspaced branch of the mailboxer gem I'm getting problems with the following: add_foreign_key "mailboxer_receipts", "mailboxer_notifications", :name…
Archonic
  • 5,207
  • 5
  • 39
  • 55
0
votes
2 answers

Edit the last generated migration in shell

I like to use Vim (and the shell) to edit my files. When I generate a migration, I often find it cumbersome to try to complete through a datetime like 20121209200054. How can I edit the last file in db/migrate (the one just generated) easily?
Jonathan Allard
  • 18,429
  • 11
  • 54
  • 75
0
votes
1 answer

Activerecord Rails 3 string limits not working

I have a rails migration and I am most probably doing something incorrect here but the migration is --- class CreateStates < ActiveRecord::Migration def change create_table :states do |t| t.string :state_legacy_id t.string :name,…
deepinder
  • 131
  • 2
  • 8
0
votes
2 answers

How do I associate a model with multiple models?

I'm a brand new developer so this might be a dumb question. I am trying to setup a webapp which will store stats on geographic data. I have a model called Stat which has fields for basic statistical information (median, variance, avg, etc.). I…
slykat
  • 856
  • 1
  • 11
  • 18
0
votes
1 answer

Rails separate DB migration not working

I am trying to run a migration to a separate DB in Rails, using establish_connection. I have something like this in the migration file: def change ActiveRecord::Base.establish_connection("user_#{Rails.env}") …
Tallmaris
  • 7,605
  • 3
  • 28
  • 58
0
votes
1 answer

Alter Schema in Rails 2

I need to add some columns to a table in my schema. Can someone tell me the best way to do this? The following seems incomplete or wrong since the schema.rb file did not update to include the new column and all of the corresponding view files…
Slinky
  • 5,662
  • 14
  • 76
  • 130
0
votes
2 answers

Rails won't recognize setting a variable to 'false'?

I have the following (simplified) model and migration: Model: class User < ActiveRecord::Base attr_readonly :contacted validates :contacted, :inclusion => { :in => [true, false] } def set_contacted self.contacted = true end def…
Bryce
  • 2,802
  • 1
  • 21
  • 46
0
votes
1 answer

How to set auto increment by 1 on a table in your migration script

How to set auto increment by 1 on a table in your migration script ALTER TABLE Table_name AUTO_INCREMENT = 1; Is it possible to mention this during table creation or after that, in your DB migration scripts.
Joe
  • 14,513
  • 28
  • 82
  • 144
0
votes
3 answers

Ruby on Rails Relationships for Two Models

I have two different models. Item Model class Item < ActiveRecord::Base belongs_to :category attr_accessible :make, :model, :name, :purchasedfrom, :qrcode, :serialnumber, :category_id end Event Model class Event < ActiveRecord::Base …
Turp
  • 708
  • 3
  • 14
  • 26
0
votes
1 answer

Is the field value going to be null if I don't add "default" to the migration method?

Here my migration: def change create_table :activities do |t| t.integer :week t.decimal :jog, :precision => 3, :scale => 1 t.integer :pushups t.integer :situps t.decimal :bicycl, :precision => 3, :scale => 1 t.integer…
Richard77
  • 20,343
  • 46
  • 150
  • 252
0
votes
1 answer

MIgration defined in gem not being executed

I added a new migration to (an existing) gem and when running the rake db:migrate command the migration is completely ignored. I tried forcing it to be run using rake db:migrate:redo VERSION=[my migration version] but it reports it cannot find the…
Anero
  • 1,406
  • 11
  • 11
0
votes
1 answer

Rake db:drop not clearing out my old tables

My User migration used to look like this: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :login etc Now it looks like this: class CreateUsers < ActiveRecord::Migration def change …
steven_noble
  • 4,133
  • 10
  • 44
  • 77
0
votes
1 answer

How the migration updates a model in Rails3.0

I am trying to add one column in one table using migration up. I have created migration for that and ran rake db:migrate:up[version] it added the column in my table but I don't see that attribute in my respective model. Am I missing something here…
user1653027
  • 789
  • 1
  • 16
  • 38