Laravel Migration with Sqlite error: typeSet does not exist

Laravel Migration with Sqlite error: typeSet does not exist

TLDR;

在 SQLite 中,是否有更好或替代的方法来使用 "set"?

完整信息

我正在尝试 运行 在 Laravel 内进行迁移,这在 MySQL 上运行良好。但是,每当尝试 运行 在 SQLite 上的测试数据库上进行相同的迁移时,我 运行 会出现以下错误:

In Macroable.php line 103:

  Method Illuminate\Database\Schema\Grammars\SQLiteGrammar::typeSet does not exist.

我知道错误是说 "set" 在 SQLite 中不存在。为了解决这个问题,我只是将 "set" 更改为 "string"。但是,这是次优的,因为我想将该字段限制为特定值。

在 SQLite 中,是否有更好或替代的方法来使用 "set"?

示例:

这是我使用 MySQL 进行的迁移,但会抛出如上所示的 typeSet 错误:

Schema::create('subscribers', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->set('test', ['one', 'two', 'three']);
    $table->timestamps();
});

这是我对 SQLite 数据库的临时修复:

Schema::create('subscribers', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('test', 255);
    $table->timestamps();
});

感谢大家的意见和建议!

(感谢@Dilip 的回答!对于其他看到此内容的人,如果您想了解更多关于 ENUM 和 SET 之间的区别,这个回答也很有帮助:MySQL enum vs. set

对于此处的设置,您可以使用枚举数据类型。在迁移文件中尝试以下格式。

$table->enum('test', ['one', 'two', 'three']);