rails-migrations

Rake db:drop not clearing out my old tables

我是研究僧i 提交于 2019-12-12 01:43:19
问题 My User migration used to look like this: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :login etc Now it looks like this: class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :username etc Why, then, do I see this? rake db:drop rake db:create rake db:migrate rails console > User.new +----+-------+------------------+---------------+-------------------+------------+------------+ | id | login | crypted_password |

Rails Migration - PG::Error: ERROR: invalid input syntax for integer: “”

南楼画角 提交于 2019-12-12 00:59:11
问题 I am trying to deploy my code to heroku and i get the error -- execute("ALTER TABLE lodges ALTER COLUMN image TYPE integer USING (image::integer)") PG::Error: ERROR: invalid input syntax for integer: "" : ALTER TABLE lodges ALTER COLUMN image TYPE integer USING (image::integer) rake aborted! and my migration is class ChangeDataTypeForLodgesImage < ActiveRecord::Migration def change execute "ALTER TABLE lodges ALTER COLUMN image TYPE integer USING (image::integer)" end end 回答1: That error is

Ruby Workflow Issue During Migration

浪尽此生 提交于 2019-12-11 13:23:17
问题 I am using Ruby Workflow in my ActiveRecords using Gem: Workflow Existing Running Code contains: I am having an ActiveRecord: X I am having two Migrations already: (Ref1) CreateX migration (which creates table X) (Ref2) CreateInitialEntryInX migration (which creates one entry in table X) New Changes: Now I wanted to add workflow in ActiveRecord X, hence I did: (Ref3) I added the workflow code in ActiveRecord Model X (mentioning :status as my workflow field) (Ref4) AddStatusFieldToX migration

How do I migrate data from production db to development db (Rails 4)?

落爺英雄遲暮 提交于 2019-12-11 12:35:03
问题 I know this one sounds kind of backwards! I've been working on a cloud-based case-management application, and was working on a support-ticketing feature. We have our development database (MySQL) that has all the same data as our production database (It's a very large app). Development is basically a "sandbox" environment, hence why the development db has all the same as the production db. This morning, I ran into a problem in my local development server for: Migrations are pending; run 'bin

Setting different default values in rails migrations?

喜夏-厌秋 提交于 2019-12-11 11:39:47
问题 I'm trying to write a migration and it looks something like this: class AddStatusToWorks < ActiveRecord::Migration def self.up change_table :works do |t| t.string :status end end def self.down change_table :works do |t| t.remove :status end end end Thing is, I want to set different default values for "status" based on a boolean value that's already in the table, "complete." If complete = true, status = "complete." If not, status = "work in progress." (The reason I want a string instead of

Neither migrations nor loading schema adds a column to Rails/MySQL database

﹥>﹥吖頭↗ 提交于 2019-12-11 07:32:22
问题 I've created a migration to add an is_ms_admin column to my MySQL database in Rails: class AddIsAdminToUsers < ActiveRecord::Migration def change add_column :users, :is_ms_admin, :boolean end end This has correspondingly updated the schema: create_table "users", force: :cascade do |t| t.string "email", limit: 255, default: "", null: false t.string "encrypted_password", limit: 255, default: "", null: false t.datetime "remember_created_at" t.integer "sign_in_count", limit: 4, default: 0, null:

How do I deal with migration name clashes?

牧云@^-^@ 提交于 2019-12-11 06:53:40
问题 I installed a shopping cart gem (Piggybak), that created a migration called create_orders... ...but I am no longer using that gem, and have added a migration to drop all tables related to piggybak. However, I am trying to roll my own shopping cart and when I created a new migration called create_order even though it has a different timestamp, I am getting this error: $ rake db:migrate [RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you

Error removing column Rails

跟風遠走 提交于 2019-12-11 06:45:21
问题 In my Rails app, I have a model called Rutinas. After some time, I needed to add some columns to the table so I generated a migration 20171116094810_add_votos_y_veces_asignada_to_rutinas.rb : class AddVotosYVecesAsignadaToRutinas < ActiveRecord::Migration[5.1] def change add_column :rutinas, :votos_pos, :integer, :default => 0 add_column :rutinas, :votos_neg, :integer, :default => 0 add_column :rutinas, :veces_asig, :integer, :default => 0 end end After some other migrations, I needed to

Rails 3 Add Foreign Key in Migration Problems

∥☆過路亽.° 提交于 2019-12-11 02:23:04
问题 Does anyone know of a way to create a foreign key in Rails 3 using migrations? 回答1: foreign_key_migrations,but I dont like that. 回答2: the foreigner gem works well for me. it adds a few methods to Rails migrations that allow easy foreign key creation and deletion: example: create_table :site_credit_payments do |t| t.decimal :amount, precision: 8, scale: 2, nil: false t.string :note, nil: true t.integer :credit_account_id t.timestamps end add_foreign_key :site_credit_payments, :credit_accounts

Rails 4: SQLException: no such table:

▼魔方 西西 提交于 2019-12-10 18:29:35
问题 i am running the following in Rails4: $ bundle exec rake db:migrate == 201405270646 AddAttachmentImageToPins: migrating =========================== -- change_table(:pins) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: SQLite3::SQLException: no such table: pins: ALTER TABLE "pins" ADD "image_file_n ame" varchar(255)c:/Sites/pinteresting/db/migrate/201405270646_add_attachment_im age_to_pins.rb:4:in block in up' c:/Sites/pinteresting/db/migrate