迁移未运行

时间:2017-11-26 20:36:07

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2

我创建了一个名为user的模型,并在timestamp_create_users.rb中(其中timestamp = long number)我有以下内容:

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(模型内部)为空。我做错了什么?

感谢您的时间

2 个答案:

答案 0 :(得分:0)

看起来您的Sqlite数据库已经有users表。如果这是开发计算机,您应该尝试

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

答案 1 :(得分:0)

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

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