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
0 answers

Rails opposite of db migrate

rake db:migrate This command is used to migrate the scaffold generated models to the database. What is the procedure to generate the models using the database.
0
votes
1 answer

Why is the user_id column of the database not being filled?

I have a table in the database called pcomment. Each pcomment belongs_to a purchase. A purchase has_many pcomments. additionally, each user has_many pcomments and each pcomment belongs_to user. In the database, the pcomments table has…
klondike-5-3226
  • 171
  • 1
  • 1
  • 9
0
votes
1 answer

How do I add a default value to columns in an existing table?

Possible Duplicate: Add a default value to a column through a migration I know it wouldn't affect existing data, but for every record going forward, I would like for there to be a default value - i.e. not null to be stored in the column. How do I…
marcamillion
  • 32,933
  • 55
  • 189
  • 380
0
votes
1 answer

Use migrations to setup test database in Rails 3

I have some raw sql statements that create triggers and functions in my migrations. They are not invoked in the tests. How can I use normal migrations to setup the test database? And why isn't that the default method?
snøreven
  • 1,904
  • 2
  • 19
  • 39
0
votes
1 answer

Differences in database.yml in rails application,host vs socket

What is the difference between following code in accessing mysql by host,socket ? adapter: mysql2 database: chart_development username: root password: root …
kanna
  • 366
  • 2
  • 19
0
votes
3 answers

Rails ActiveRecord implementing relationship

Help me out with a db migration and model in Rails, I tried searching for self referencing and what not, but I can't make heads or tails.. I'm stuck, so to say.. Basically I want two models, User model and Rule model. In User model I want to…
0
votes
3 answers

Rename each entry (or row) of a column in a rails migration

I want to remap values in my status column based on a hash. For example if the status is a, change it to b. How do I do this in Rails and optimize it so that it executes one db call that changes all values in the column?
n00shie
  • 1,741
  • 1
  • 12
  • 23
0
votes
1 answer

Rails - converting data during migrations

I'm splitting out some data from a model into a new one and creating an association between them. I've added the new_model_id to OldModel, created NewModel with address as a string attribute, and have the following migrations: class…
bdx
  • 3,316
  • 4
  • 32
  • 65
0
votes
2 answers

Migrations creating defunct tables

ENVIRONMENT ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]; Rails 3.2.6; OSX 10.6.8 PROBLEM Even after resetting our database (rake db:reset), migrations are generating erroneous tables, fields, and schemas, featuring tables,…
mike montagne
  • 151
  • 2
  • 7
0
votes
1 answer

Active record migrations and refactoring

I'm in the midst of a fairly steep bit of refactoring on my current project. Previous to reaching this crossroads I have two models that I came to realize are really the same model but with in a different state and I want to represent the system…
jaydel
  • 14,389
  • 14
  • 62
  • 98
0
votes
2 answers

My production database is missing some columns. How can I safely restore them?

After making some major modifications to a Rails app that is already in production, I pushed everything to the server, ran my migrations and then discovered major problems. It turns out that there are 2 database columns that have not been created in…
brad
  • 9,573
  • 12
  • 62
  • 89
0
votes
1 answer

Rails migrations best practise- many similar migrations or one big?

I have to add one column to almost 10 tables. What do you think is the best way to do that? Make a one migration with weird name and use a loop to change column in each model Make 10 migrations with similar content but having nice names like:…
Piotr Brudny
  • 654
  • 4
  • 16
0
votes
1 answer

RnR: Database normalization, rails models and associations

Ok, so I have three different objects: a person, place, and equipment. Each can have an address, in most cases multiple address and multiple phone numbers. So my thought is create the specific object tables, the have an address and a phone table. …
0
votes
1 answer

Migration from existing Java EE project to maven without changing directory layout

I have seen many questions concerning this issue, but I'm new to this topic and I have to convert previously written project (standard, Eclipse Java EE project) into Maven. My first problem is that I'm completely new to Maven. Second - I can't…
Olek Olkuski
  • 93
  • 2
  • 8
0
votes
2 answers

heroku run rake db:migrate error

I want do run migration on my app that I have on heroku but I get this error: Running `rake db:migrate` attached to terminal... up, run.1 DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be…
user592638