在Rails上创建用户的设计不起作用

时间:2019-02-02 14:27:23

标签: ruby-on-rails devise

我创建了一个迁移,用于通过 Devise 生成用户模型,如下所示:

  rails g devise User

然后我通过 Devise 创建一些视图:

  rails g devise:views

现在,当我运行 rails db:migrate 时,出现以下错误:

C:\Users\andri\Desktop\hoagieShop\hoagieShop>rails db:migrate
== 20190202141046 AddDeviseToUsers: migrating =================================
-- change_table(:users)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190202141046_add_devise_to_users.rb:7:in `block in up'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190202141046_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'

Caused by:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190202141046_add_devise_to_users.rb:7:in `block in up'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190202141046_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'

Caused by:
SQLite3::SQLException: no such table: users
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190202141046_add_devise_to_users.rb:7:in `block in up'
C:/Users/andri/Desktop/hoagieShop/hoagieShop/db/migrate/20190202141046_add_devise_to_users.rb:5:in `up'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

这是迁移中的代码:

class AddDeviseToUsers < ActiveRecord::Migration[5.0]
  def self.up
    change_table :users do |t|
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

    end

    add_index :users, :email,                unique: true
    add_index :users, :reset_password_token, unique: true

  end

  def self.down
    raise ActiveRecord::IrreversibleMigration
  end
end

有人知道为什么会这样吗?感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试此命令

myObject