0
==  AddAncestryToMessages: migrating ==========================================
-- add_column(:messages, :ancestry, :string)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: messages: ALTER TABLE "messages" ADD "ancestry" varchar(255)

そのため、私のアプリケーションには投稿できるメッセージ (Twitter のようなもの) があり、返信を追加しています。そのために ancestry gem を使用しています。

ファイル内の私のコードschema.rb(これは、rake db:migrate を実行するたびにテーブルを作成するために使用するファイルだと思いますが、間違っている可能性があります (これが問題になる可能性があります!)

  create_table "messages", :force => true do |t|
    t.string   "content"
    t.integer  "user_id"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.string   "ancestry"
  end

  add_index "messages", ["user_id", "created_at", "ancestry"], :name =>   "index_messages_on_user_id_and_created_at_and_ancestry"
4

1 に答える 1

0

ああ、わかりました。コードをに追加しましたschema.rbが、移行を使用する必要がありました。手動で追加したコードをから削除してschema.rb実行します。

rails g migration CreateMessages

ファイルdb/migrate /[timestamp]_create_messages.rbを取得します。そのchangeメソッドにコードを入力してから実行します(作成する必要がありますが、空です。古いバージョンの場合は名前が付けられますup):

rake db:migrate

このコマンドはschema.rbそれ自体を変更します。手動で変更しないでください。(少なくとも、成熟したRailsプログラマーになるまで)。

于 2012-05-08T06:30:15.067 に答える