【发布时间】:2020-05-18 10:23:21
【问题描述】:
TLDR;
在 SQLite 中,是否有更好或替代的方式来使用“set”?
完整信息
我正在尝试在 Laravel 中运行迁移,这在 MySQL 上运行良好。但是,每当尝试在 SQLite 上的测试数据库上运行相同的迁移时,都会遇到以下错误:
In Macroable.php line 103:
Method Illuminate\Database\Schema\Grammars\SQLiteGrammar::typeSet does not exist.
我了解该错误表明 SQLite 中不存在“set”。为了解决这个问题,我只是将“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();
});
感谢大家的cmets和建议!
(感谢@Dilip 的回答!对于看到此内容的其他人,如果您想了解更多有关 ENUM 和 SET 之间区别的信息,此答案也很有帮助:MySQL enum vs. set)
【问题讨论】:
标签: laravel sqlite laravel-migrations