gpt4 book ai didi

mysql - 通过 ruby​​ Rails 迁移添加 MySQL 枚举列时出现问题

转载 作者:行者123 更新时间:2023-11-29 16:02:42 27 4
gpt4 key购买 nike

我正在尝试通过执行以下操作来添加 MySQL 枚举列:

# frozen_string_literal: true
class AddStatusToTasks < ActiveRecord::Migration[6.0]
def up
execute <<-SQL
ALTER TABLE tasks ADD status enum('to_do', 'doing', 'done');
SQL
end
def down
remove_column :tasks, :status
end
end

但我收到错误:

AddStatusToTasks: migrating =================================
-- execute(" ALTER TABLE tasks ADD status enum('to_do', 'doing', 'done');\n")
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: near "'to_do'": syntax error

我的模特喜欢的样子:

class Task < ApplicationRecord
belongs_to :user
enum status: { to_do: 'to_do', doing: 'doing', done: 'done' }
end

我实际上正在遵循指南 here ,但我找不到问题所在。

提前感谢大家的帮助!

最佳答案

SQLite3::SQLException -- 您正在 SQLite 数据库而不是 MySQL 上执行此查询。您使用的环境正确吗?

关于mysql - 通过 ruby​​ Rails 迁移添加 MySQL 枚举列时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56042635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com