【问题标题】:no such function: NOW during migration没有这样的功能:现在在迁移期间
【发布时间】:2017-04-28 05:40:48
【问题描述】:

在 Ruby on Rails 中,我正在为用户迁移创建一个可确认的设计,但是当我迁移时出现错误:

StandardError:发生错误,此迁移和所有后续迁移 取消

SQLite3::SQLException:没有这样的功能:现在:更新用户集 Confirmed_at = NOW()

迁移:

class AddConfirmableToDevise < ActiveRecord::Migration[5.0]
  def up
    add_column :users, :confirmation_token, :string
    add_column :users, :confirmed_at, :datetime
    add_column :users, :confirmation_sent_at, :datetime
    # add_column :users, :unconfirmed_email, :string # Only if using reconfirmable
    add_index :users, :confirmation_token, unique: true
    # User.reset_column_information # Need for some types of updates, but not for update_all.
    # To avoid a short time window between running the migration and updating all existing
    # users as confirmed, do the following
    execute("UPDATE users SET confirmed_at = NOW()")
    # All existing user accounts should be able to log in after this.
    # Remind: Rails using SQLite as default. And SQLite has no such function :NOW.
    # Use :date('now') instead of :NOW when using SQLite.
    # => execute("UPDATE users SET confirmed_at = date('now')")
    # Or => User.all.update_all confirmed_at: Time.now
  end

  def down
    remove_columns :users, :confirmation_token, :confirmed_at, :confirmation_sent_at
    # remove_columns :users, :unconfirmed_email # Only if using reconfirmable
  end
end

【问题讨论】:

    标签: ruby-on-rails devise sqlite


    【解决方案1】:

    引用你的问题:

    # Use :date('now') instead of :NOW when using SQLite.
    # => execute("UPDATE users SET confirmed_at = date('now')")
    

    【讨论】:

      猜你喜欢
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2020-04-15
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多