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

rake db:migrate does not working

I am updgrading a redmine instance from a very early version. I am doing exact what the tutorial says. However command rake db:migrate rails_env=production doesn't modify the database correctly. There are a lot of fields not added to tables. I…
Luyin Sun
  • 1,124
  • 1
  • 9
  • 21
0
votes
2 answers

Do undo for a migration

There is a migration which has been applied and commited to github. It contains a custom code, meaning it's to do "down". In fact, the method "down" is empty.I can delete a db and it's ok since there is not much the data in it. Now I need to change…
user266003
0
votes
2 answers

In Rails, how do I go over a db migration without executing it?

So I jumped onto this Rails project at work and I have my own copy of it running on my local devbox. I tried to run the tests to see what the results were but rake came back complaining that I had 5 outstanding migrations to do first. I first just…
grg-n-sox
  • 717
  • 2
  • 5
  • 25
0
votes
2 answers

How to Reverse a Migration that Requires a Gem

I recently tested the Queue_Classic gem in my app. Part of the setup is running this migration: require 'queue_classic' class AddQueueClassic < ActiveRecord::Migration def self.up QC::Setup.create end def self.down QC::Setup.drop …
mattangriffel
  • 819
  • 1
  • 7
  • 18
0
votes
1 answer

How do I change the name of a model generated by scaffold cleanly?

I have a model called ModelA that I want to rename to ModelB. I generated ModelA by doing rails g scaffold ModelA. That generated the model, controller, views, specs, routes, etc. How do I cleanly change the name of ModelA given that I have setup…
marcamillion
  • 32,933
  • 55
  • 189
  • 380
0
votes
1 answer

Rails: Canceled `rails g migration` command and now I can't run later migrations

I was trying to change a column datatype and initially wrote a rails g migration command to change the column's datatype; however, the process in my terminal window just hung up and appeared to not do anything. So then I proceeded to make a class…
daveomcd
  • 6,367
  • 14
  • 83
  • 137
0
votes
1 answer

rails migration - update column with constraints

How to add new column and update its value from another table's column with conditions ? I'm having two tables named user id: integer name: string preferred_communication_channel_id: integer // stores the id of communication_channel and table…
Siva
  • 7,780
  • 6
  • 47
  • 54
0
votes
1 answer

Is it possible to mix migrations file without harmful consequences?

Let me explain : I followed the M. Hartl tutorial and I did just like him with migrations. So now, I have the followings files in my db/migrate directory (I spare you the timestamps): create_users.rb class CreateUsers < ActiveRecord::Migration def…
Flo Rahl
  • 1,044
  • 1
  • 16
  • 33
0
votes
1 answer

How do I fix a botched migration that didn't remove a column?

I made a migration to remove a column from my first app ever about a week ago: class RemoveHalfOrFullFromFurlough < ActiveRecord::Migration def up remove_column :furloughs, :half_or_full end def down add_column :furloughs,…
Alaric
  • 229
  • 1
  • 12
0
votes
1 answer

Rails Migrations: How to split one table into two tables?

I have a database with the following schema: [ Region ] 1 --- * [ District ] 1 --- * [ Location ] I would like to split the middle table into two tables as follows: [ Region ] 1 --- * [ District ] 1 --- * [ Area ] 1 --- * [ Location ] ...leaving…
0
votes
1 answer

Changing Model associations after running migration

I have a Devise User model with the following contents for which I did run migration. class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and…
0
votes
1 answer

Adding :scale to a column in a table already filled with data(non scaled) and Updating existing values-Rails 3

i have a migration file class CreateProductDetails < ActiveRecord::Migration def change create_table :product_details do |t| t.integer :quantity , :default => 1 t.float :price , :default => 0.0 t.float :fee ,…
user2164011
0
votes
2 answers

Database structure in a Rails project and keep track of migrations

So after alot of reading i found out that i dont need to plan my database ahead. I just start working on the application and do migrations on every change. So for example if I decide to add something I add it via migration. Then on another migration…
0
votes
1 answer

rake db:migrate rake aborted! unable to determine name from existing gemspec

I am trying to rake db:migrate. I cloned a repository and tried to rake db:migrate, but get this error : rake aborted! Unable to determine name from existing gemspec. Use :name => 'gemname' in #inst ll_tasks to manually set it.…
ishwr
  • 725
  • 3
  • 14
  • 36
0
votes
1 answer

Rails calling Models in the Migration

I have a migration that creates a table, and I need to access the model for that table to create another table. The migration seems to not recognized that the original table has been created, so to make sure I put a debugger in my code and when I…
Matilda
  • 1,708
  • 3
  • 25
  • 33