rails-migrations

How do I disable the migrations feature in a Rails app?

强颜欢笑 提交于 2019-12-19 04:21:10
问题 Background We engineer database models and application models separately (RDMBS architects vs OOP engineers). From what I've seen regarding Rails versus domain/key normal form, Rails migrations cannot easily duplicate all the features of a well-designed enterprise RDBMS (if at all) so we don't migrate and instead use other tools to build databases (nevermind the problem of object-relational impedance mismatch). Data integrity and DB performance are too valuable to us to risk RDBMS model

Delete old migrations files in a Rails app

旧时模样 提交于 2019-12-18 11:48:03
问题 Is it permissible to delete (or archive) old migration files in a Rails app if the schema is stable? My migrations are numerous and I suspect there may be some problem in there somewhere, because I occasionally have problems migrating the database on Heroku. 回答1: You don't need to keep around your old migration files in a Rails app, because your database schema should be captured either in schema.rb or an equivalent SQL file that can be used to regenerate your schema. Migrations are not the

Rails: “t.references” not working when creating index

江枫思渺然 提交于 2019-12-18 05:46:35
问题 class CreateBallots < ActiveRecord::Migration def change create_table :ballots do |t| t.references :user t.references :score t.references :election t.string :key t.timestamps end add_index :ballots, :user add_index :ballots, :score add_index :ballots, :election end end results in: SQLite3::SQLException: table ballots has no column named user: CREATE INDEX "index_ballots_on_user" ON "ballots" ("user")/home/muhd/awesomevote/db/migrate/20130624024349_create_ballots.rb:10:in `change' I thought t

How do I move a column (with contents) to another table in a Rails migration?

蓝咒 提交于 2019-12-17 21:49:49
问题 I need to move some columns from one existing table to another. How do I do it using a rails migration? class AddPropertyToUser < ActiveRecord::Migration def self.up add_column :users, :someprop, :string remove_column :profiles, :someprop end def self.down add_column :profiles, :someprop, :string remove_column :users, :someprop end end The above just creates the new columns, but values are left empty... I want to avoid logging in to the database to manually update the tables. If there is a

Rails Migration Error w/ Postgres when pushing to Heroku

可紊 提交于 2019-12-17 18:39:11
问题 I'm trying to perform the following up migration to change the column "number" in the "tweet" model's table class ChangeDataTypeForTweetsNumber < ActiveRecord::Migration def up change_column :tweets do |t| t.change :number, :integer end end def down change_table :tweets do |t| t.change :number, :string end end end Upon performing the the following up migration to heroku.... heroku rake db:migrate:up VERSION=20120925211232 I get the following error PG::Error: ERROR: column "number" cannot be

Rails Migrations: tried to change the type of column from string to integer

这一生的挚爱 提交于 2019-12-17 10:52:49
问题 I created a table in my rails app with rails generate migrations command. Here is that migration file: class CreateListings < ActiveRecord::Migration def change create_table :listings do |t| t.string :name t.string :telephone t.string :latitude t.string :longitude t.timestamps end end end Then I wanted to store the latitude and longitude as integers so I tried to run: rails generate migration changeColumnType and the contents of that file are: class ChangeColumnType < ActiveRecord::Migration

PG::UndefinedTable: ERROR: relation “…” does not exist

半世苍凉 提交于 2019-12-17 07:37:59
问题 On migration I get the following error message: PG::UndefinedTable: ERROR: relation "actioncodes" does not exist : ALTER TABLE "organizations" ADD CONSTRAINT "fk_rails_4ecaa2493e" FOREIGN KEY ("actioncode_id") REFERENCES "actioncodes" ("id") I have the following migration file for Organizations: class CreateOrganizations < ActiveRecord::Migration def change create_table :organizations do |t| t.string :name, null: false, limit: 40 t.references :actioncode, index: true, foreign_key: true t

Rails migrations over an existing database

谁说我不能喝 提交于 2019-12-13 13:13:40
问题 I am creating a new Rails 3.1 application. I would like this new application to reuses an existing database (which was created by a previous rails 2 application). I created the new application defining models that reuses some of the existing data in the database. In the development and test phase everything works fine since it runs on a clean sheet database, but when trying to deploy to production I get messages such as: PGError: ERROR: column "email" of relation "users" already exists ***

Changes in a model not saving. Rails 4.1

五迷三道 提交于 2019-12-12 10:27:02
问题 I've just created a user model using scaffolding, as follows: rails g scaffold user name:string I run db:migrate and everything works fine, but when I try to add a new field, it is not saving it in the database. I add the field by doing: rails g migration add_surname_to_users surname:string No weird messages when I run rake db:migrate, the database table is ok, the form has been edited to alow surname input, as it have the show and index views to display it properly. However, it is not saving

ActiveModel::MissingAttributeError: can't write unknown attribute `user_id`

喜你入骨 提交于 2019-12-12 01:47:19
问题 I am trying to implement a "comment" feature as part of my assignment for an project I am building. Earlier in the course we created a comment table and had the Faker gem generate fake comments. My instructions are as follows: Comments must be associated with users, so add a user_id foreign key to the comments table. Remember to add an index to it too; Update the User model so you can call user.comments, and the Comment model so you can call comment.user; Modify the seeds.rb file to create