迁移不是 运行

migrate is not running

我制作了一个名为 user 的模型,在 timestamp_create_users.rb(其中时间戳 = 长数字)中我有以下内容:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|

      t.integer :userNum, :limit => 7
      t.string :username, :limit => 32
      t.string :fname, :limit => 40
      t.string :surname, :limit => 40
      t.string :email, :limit => 50
      t.string :kNum, :limit => 8
      t.string :password, :limit => 80
      t.boolean :isTeacher, :default => false
      t.timestamps null: false

    end
  end
end

问题是它给了我一条很长的错误信息,这里是它的标题:

rake db:migrate

== 20171126181930 CreateUsers: migrating ======================================
-- create_table(:users)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "userNum" integer(7), "username" varchar(32), "fname" varchar(40), "surname" varchar(40), "email" varchar(50), "kNum" varchar(8), "password" varchar(80), "isTeacher" boolean DEFAULT 'f', "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) 

并且 user.rb(模型内部)是空的。我做错了什么?

感谢您的宝贵时间

看起来您的 Sqlite 数据库已经有 users table。如果这是 开发 机器你应该尝试

rake db:drop
rake db:create
rake db:migrate

运行 耙子db:setup ,它基本上运行以下所有命令,它将解决您的错误并在单个命令中设置您的应用程序

rake db:drop
rake db:create
rake db:migrate
rake db:seed