###前提・実現したいこと
すでに作成してしまったカラムの型を変更したい。
ターミナルにて、
rails g model Listing travel_departure:integer
と実行してしまったのですが、placeの型をinteger→stringに変更したいです。
実際には、
rails g model Listing travel_departure:string
としたかったということです。
###実際に行ったこと
rails g migration change_datatype_travel_departure_of_listings
を実行しました。
↓
db/migrate/20180112034439_change_datatype_travel_departure_of_listings.rb
が作成されました。
↓
###db/migrate/20180112034439_change_datatype_travel_departure_of_listings.rb
class ChangeDatatypeTravelDepartureOfListings < ActiveRecord::Migration[5.1] def change change_column :listing, :travel_departure, :string end end
↓
rails db:migrate
実行
↓
###エラーコード
== 20180112034439 ChangeDatatypeTravelDepartureOfListings: migrating ========== -- change_column(:listings, :travel_departure, :string) rails aborted! StandardError: An error has occurred, this and all later migrations canceled: SQLite3::ConstraintException: FOREIGN KEY constraint failed: DROP TABLE "listings" /Users/hikaru/Desktop/TS/vendor/bundle/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb:108:in `step'
参考にしたサイト通りに行ったのですが、うまくいきません。
参考にしたのは、こちらのURLです。
https://qiita.com/dawn_628/items/13fa64dc6d600e921ce3
ご教授のほど、よろしくお願いいたします。
###(追記)db/schema.rb
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # database schema. If you need to create the application database on another # system, you should be using db:schema:load, not running all the migrations # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 20180109075510) do create_table "listings", force: :cascade do |t| t.string "travel_type" t.string "travel_country" t.integer "travel_departure" t.integer "travel_arrival" t.string "address" t.string "listing_title" t.text "listing_content" t.boolean "active" t.integer "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "price" t.float "latitude" t.float "longitude" t.index ["user_id"], name: "index_listings_on_user_id" end create_table "photos", force: :cascade do |t| t.integer "listing_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "image_file_name" t.string "image_content_type" t.integer "image_file_size" t.datetime "image_updated_at" t.index ["listing_id"], name: "index_photos_on_listing_id" end create_table "reservations", force: :cascade do |t| t.integer "user_id" t.integer "listing_id" t.integer "number" t.datetime "by_time" t.integer "price" t.integer "total_price" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "commodity_prices" t.index ["listing_id"], name: "index_reservations_on_listing_id" t.index ["user_id"], name: "index_reservations_on_user_id" end create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "provider" t.string "uid" t.string "image" t.string "name" t.string "phone_number" t.string "description" t.integer "price" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end end
回答1件
あなたの回答
tips
プレビュー