###前提・実現したいこと
ruby 初心者です。
ruby on rails 5.1.3 で参考書に沿って勉強していたところ、以下のようなエラーメッセージが発生しました。
###発生している問題・エラーメッセージ
SQLite3::SQLException: no such table: messages: SELECT "messages".* FROM "messages"```
messages というテーブルがないのかなと思い、
rails c から ActiveRecord::Base.connection.tables を実行したところ
確認することができませんでした。
しかし、rails g model message、rails db:migrate を行ったので、テーブルを作れたものだと考えています。。。
class CreateMessages < ActiveRecord::Migration[5.1] def change create_table :messages do |t| t.integer :person_id t.text :title t.text :message t.timestamps end end end
どこがどのように間違っているのか、また、今回私が行った ActiveRecord::Base.connection.tables 等の確認方法について間違えがありましたら、教えていただけるとありがたいです。
よろしくお願いいたします。
###追記です!! migration 実行時のログです
== 20170826062313 CreatePeople: migrating ===================================== -- create_table(:people) rake aborted! StandardError: An error has occurred, this and all later migrations canceled: SQLite3::SQLException: table "people" already exists: CREATE TABLE "people" ("id " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" text, "age" integer, "mail" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /home/vagrant/rails_lessons/RailsApp/db/migrate/20170826062313_create_people.rb: 3:in `change' ActiveRecord::StatementInvalid: SQLite3::SQLException: table "people" already ex ists: CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "n ame" text, "age" integer, "mail" text, "created_at" datetime NOT NULL, "updated_ at" datetime NOT NULL) /home/vagrant/rails_lessons/RailsApp/db/migrate/20170826062313_create_people.rb: 3:in `change' SQLite3::SQLException: table "people" already exists /home/vagrant/rails_lessons/RailsApp/db/migrate/20170826062313_create_people.rb: 3:in `change' Tasks: TOP => db:migrate (See full trace by running task with --trace)
###補足情報(言語/FW/ツール等のバージョンなど)
centos からvagrant を起動させて動作させています。
回答3件
あなたの回答
tips
プレビュー