5

TLDR;

Within SQLite, is there a better or alternative way to use "set"?

Full Information

I am trying to run a migration within Laravel, which works fine on MySQL. However, whenever trying to run the same migration on a testing database on SQLite, I run into the following error:

In Macroable.php line 103:

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

I understand that the error is stating that "set" does not exist within SQLite. In order to fix this, I simply changed "set" to "string". However, this is suboptimal, as I would like to limit that field to specific values.

Within SQLite, is there a better or alternative way to use "set"?

Example:

Here is my migration that works with MySQL, but throws the typeSet error as seen above:

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

Here is my temporary fix for the SQLite database:

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

Thanks everyone for your comments and suggestions!

(Thanks @Dilip for your answer! For anyone else seeing this, if you want to know more about the difference between ENUM and SET, this answer was also helpful: MySQL enum vs. set)

1 Answer 1

9

for set here you may use enum datatype. try below format in the migration file.

$table->enum('test', ['one', 'two', 'three']);
Sign up to request clarification or add additional context in comments.

3 Comments

You are absolutely right @Dilip :) Thanks so much for your help! :) :)
Underrated answer. This saved me so much time. I wish I could upvote more than once.
@MartinDimitrov Np, I'll do it for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.