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

add_index error [Ruby on Rails]

I am trying to create a "one-to-many relationship between owner and property" but I don't know why I am getting this error, after generating a model I tried to add_index before run rake db:migrate but something went wrong Note: It's the first time…
0
votes
1 answer

Error when adding foreign key in ActiveRecord Migration

I have the following db/migrate ruby file. When I tried rake db:migrate, it gave error. class CreateEmployers < ActiveRecord::Migration def self.up create_table :employers, {:primary_key => 'emp_id'} do |t| t.column…
Lwin Htoo Ko
  • 2,326
  • 4
  • 26
  • 38
0
votes
3 answers

Linking two objects to a single record in rails active record

I'm trying to make two one to one relationships in the same class in rails. I added two columns to my class called link post_id1 post_id2 So now I want to be able to get a link object, and do link.post1 link.post2 But I'm getting confused about…
Chris Barry
  • 4,564
  • 7
  • 54
  • 89
0
votes
1 answer

rails migration remove keys and add data into auto-increment column id

I have php application with below table structure CREATE TABLE IF NOT EXISTS `artist_has_fans` ( `artist_id` int(11) NOT NULL, `fan_id` int(11) NOT NULL, PRIMARY KEY (`artist_id`,`fan_id`), KEY `fk_artist_has_artist_artist2` (`fan_id`), KEY…
pramodtech
  • 6,300
  • 18
  • 72
  • 111
0
votes
1 answer

How do I sort the migration script folder in a ascending fashion

How do I sort the migration script folder in a ascending fashion (i.e. I want the recently created scripts to come at the bottom when I do a ls -l command). Currently its coming in a mixed fashion.
Rpj
  • 5,348
  • 16
  • 62
  • 122
0
votes
1 answer

rails with carrierwave migration error: undefined method `attachment'

I'm using carrierwave gem ( ver. 0.8.0 ). When I make 'rake db:migrate', I see strange error: == AddAttachmentLogoToMerchants: migrating =================================== -- change_table(:merchants) rake aborted! An error has…
bmalets
  • 3,207
  • 7
  • 35
  • 64
0
votes
1 answer

Rails: last migration reapplied

Sometimes rake db:migrate tries to run migrations which have already been successfully migrated (without any errors). When I check the schema_migrations table, the repetitive migration is not there. I've noticed that this only happens when I use…
Nurbo
  • 115
  • 6
0
votes
1 answer

rake migrate aborted for undefined local variable or method

Got a issue when i run rake db:migrate. The mistake message is like -- create_table(:addresses) -> 0.1792s -- contact_id() rake aborted! An error has occurred, this and all later migrations canceled: undefined local variable or method…
Ray-Von-Mice
  • 429
  • 1
  • 4
  • 16
0
votes
1 answer

Skip validations on ActiveRecord concat during migration?

I have a migration that uses the ActiveRecord concat method to add an object to another object's has_many relationship. Since creating the migration, I have added a new attribute to the parent model that includes a validation. Unfortunately, the…
0
votes
0 answers

Create rails migration files from admin web interface

I'm looking at the best way to manage a dynamic models in rails from a web interface; for example lets say i have a product model and from the admin web interface I want to be able to add a new field/column with the related data type (e.g. a new…
0
votes
1 answer

How to Handle ActiveRecord Migrations in a Distributed Gem?

I am trying to write an app as a gem using ActiveRecord without Rails. My problem is how to migrate a database already deployed by a user who will not have rake, etc. I have just distributed a schema.rb file and created the db from that. But now I…
ddoherty
  • 275
  • 1
  • 3
  • 14
0
votes
1 answer

Best solution for doing database migration on mysql?

I currently facing one problem when doing the migration especially adding new field to existing table which contains millions of records will take very long duration to complete. So I wonder is there any special trick way to make it migrate fast?
pang
  • 3,964
  • 8
  • 36
  • 42
0
votes
1 answer

Update forms template rails 3

this question may sound silly but i wanted to know if there way a way to update the form and model once we change a database. For example when i generate scaffolding i may forget 2 fields that i need to put in the db and when i remember them later…
deepinder
  • 131
  • 2
  • 8
0
votes
1 answer

my schema has a "messages" table I can't drop with migration

My schema has a messages table that I can't drop with a migration. When I try to drop the table I get PG::Error: ERROR: relation "messages" does not exist. How can this be if the schema.rb is the authoritative source for your database schema?
0
votes
2 answers

what am I doing wrong? undefined method `comment_content'

I followed this page step-by-step Micropost's comments on users page (Ruby on Rails) then I looked into my error that I'm getting here form_for , undefined method name I ran "rails generate migration add_comment_content_to_micropost…
Amy Brown
  • 117
  • 2
  • 9