【问题标题】:Laravel Migration with Sqlite error: typeSet does not exist带有 Sqlite 错误的 Laravel 迁移:typeSet 不存在
【发布时间】: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


    【解决方案1】:

    在这里设置你可以使用枚举数据类型。在迁移文件中尝试以下格式。

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

    【讨论】:

    • 你是绝对正确的@Dilip :) 非常感谢你的帮助! :) :)
    • 被低估的答案。这为我节省了很多时间。我希望我可以多次投票。
    猜你喜欢
    • 2018-07-06
    • 2014-06-23
    • 2020-05-07
    • 2018-06-05
    • 2019-03-31
    • 2014-06-10
    • 2015-12-19
    • 2017-06-18
    相关资源
    最近更新 更多