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

ActiveRecord connectionPool in rails 3.2 not creating table in the correct database

I'm working on upgrading my project from rails 3.0.9 to rails 3.2.5. I'm using multiple databases and when running the migration in rails 3.2.5 everything runs ok but everything it's created in the default database instead of it's corresponding…
Giancarlo Corzo
  • 1,976
  • 5
  • 24
  • 36
0
votes
1 answer

Heroku migrations that accept user's input

I have a Rails migration that looks like this: puts "*** What would you like to do? ***" puts "(a)dd columns AND copy data" puts "(c)olumns only (no data copying)" puts "(d)ata only (no column adding)" puts "(q)uit" reply =…
sscirrus
  • 55,407
  • 41
  • 135
  • 228
0
votes
1 answer

I'm using rake for a non-rails app, and migrations using active-record. How to run seeds?

I have a non-rails application where I use both rake and activerecord for my db migrations etc. How could I use seeds? I created a seeds.rb file, but how to wrap it in a rake method call?
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
0
votes
1 answer

Password_Digest has problems when new columns are added

I've got a user model for my app, and it has effectively used has_secure_password up til this point. has_secure_password necessitates a password_digest column, and herein lies my recent problem. I wanted to create a "role" column of type string…
cognalog
  • 440
  • 5
  • 8
0
votes
1 answer

add_index not working in Rails 3

I'm in a Rails 3.2.3 app and I'm adding index for the foreign keys in my database migrations. However, when after running the migrations the keys don't seem to be indexed. I've tested directly via the mysql console. That's what I've done, better…
0
votes
1 answer

database migrations while deploying rails app

I'm curious about where I should run "rake db:migrate RAILS_ENV="production" when I'm deploying to my server. Should I run it locally and then deploy? Or should I deploy then run the migration from the /current directory on the server? Thanks in…
J K
  • 495
  • 2
  • 7
  • 22
-1
votes
1 answer

Rails model default value being ignored when new record created?

I have a Message model like so class CreateMessages < ActiveRecord::Migration[6.0] def change create_table :messages do |t| t.text :body t.references :conversation, null: false, foreign_key: true t.references :user, null:…
stevec
  • 41,291
  • 27
  • 223
  • 311
-1
votes
1 answer

Rails can a enum role column in User table be referenced in multiple tables?

I have a User model with a Role attribute, which I defined using enum. enum role: {'Instructor': 0, 'Student': 1, 'Other': 2} Now, I have another table Instructor with references from User table. I have a Course table with references from…
Sai Sagar
  • 5
  • 3
-1
votes
1 answer

How to add has_many association to two different model in rails migration?

How can i accomplish this? class User < ActiveRecord::Base has_many :old_posts has_many :new_posts end I already have has_many relation to old_posts model. I would like to add another has_many relation to new_posts. The old_posts and…
-1
votes
1 answer

With Rails Minitest how do I recreate views on db migration for my test database?

I'm using Rails 5 with Minitest 5.9. I have some views in my application for complex queries. Everytime I create a new migration my test database removes my views and I have to recreate them. How do I automate the view recreation?
David Silva Smith
  • 11,498
  • 11
  • 67
  • 91
-1
votes
1 answer

Removing a database unique index constraint in postgres Rails

In my Rails structure.sql, I have this line of code: CREATE UNIQUE INDEX primary_active_fruit_in_season_constraint ON trees USING btree (user_id) WHERE (is_ripe AND is_in_season); I no longer need this validation so I am going to remove the…
Jwan622
  • 11,015
  • 21
  • 88
  • 181
-1
votes
2 answers

First course table to add a field open, type Boolean;rake db:migrate Operation error?

class AddOpenAttributeToCourses < ActiveRecord::Migration def change add_column :courses, :open, :boolean change_column_default(:courses, :open, {:from=>true, :to=>false}) end end !!!!!then Operation!!!!!! rake db:migrate ==…
wcyd
  • 1
  • 1
-1
votes
2 answers

Set nickname to name in downcase in RAILS migration

I'm using a User Model in which name column is there, but now I want to add a nickname column with default of nickname being the name of the user in downcase. How this can be achieved?
s_a
  • 65
  • 9
-1
votes
1 answer

How to let rails only check current database's migration

I use rails 4 , and has to migrate folder under db/migrate,for example: db/migrate/A , db/migrate/B . I have success used A migration file create A database schema , used B migration file create B database schema . But when i connect A database ,…
-1
votes
1 answer

How to fix commits with conflicting migrations?

Suppose there's a migration that creates some records and there are two commits that look like this # commit 1 by Alice # migration def up create_table :cities do |t| t.string :name end City.create!(name: 'New York') …
1 2 3
68
69