我还是Rails的新手,所以也许有一个简单的答案。我想在我的“users”表中添加一个“user_category”列,该列引用了一个“user_categories”表。我尝试了以下内容:
rails generate migration add_user_category_to_users user_category:integer
and then...
rails generate scaffold User_Category title:string description:text
但是在运行 rake db:migrate 命令时,我收到了以下错误提示:
== CreateUserCategories: migrating ===========================================
-- create_table(:user_categories)
rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: table "user_categories" already exists: CREATE TABLE "user_categories" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "description" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
任何帮助都将不胜感激。
User
拥有多个Categories
,而一个Category
属于一个User
。我错了吗? - MrYoshiji