Alm*_*itt 5 sqlite laravel laravel-migrations
太长了;
在 SQLite 中,是否有更好或替代的方法来使用“set”?
完整信息
我正在尝试在 Laravel 中运行迁移,它在 MySQL 上运行良好。然而,每当尝试在 SQLite 上的测试数据库上运行相同的迁移时,我都会遇到以下错误:
In Macroable.php line 103:
Method Illuminate\Database\Schema\Grammars\SQLiteGrammar::typeSet does not exist.
Run Code Online (Sandbox Code Playgroud)
我知道该错误表明 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();
});
Run Code Online (Sandbox Code Playgroud)
这是我对 SQLite 数据库的临时修复:
Schema::create('subscribers', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('test', 255);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
感谢大家的意见和建议!
(感谢@Dilip的回答!对于看到此内容的其他人,如果您想了解更多有关 ENUM 和 SET 之间的区别,这个答案也很有帮助:MySQL enum vs. set)
对于此处的设置,您可以使用枚举数据类型。在迁移文件中尝试以下格式。
$table->enum('test', ['one', 'two', 'three']);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1016 次 |
最近记录: |