2

I have a column called owner_type in a table called events. This column is filled with one of two values: 0 (signalling regular users) and 1 (for business users).

This column has a data type string, I'd like to change it to integer given that it'll always contain 0s and 1s. So I did this:

public function up()
{
    Schema::table('events', function (Blueprint $table) {
        $table->integer('owner_type')->change()->default(0);
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('events', function (Blueprint $table) {
        $table->string('owner_type')->default(0)->change();
    });
}

However, I receive this error:

n AbstractPlatform.php line 461:

Unknown database type enum requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it.

In the migration that created events I have:

    $table->enum('**', ['**', '**'])->default('**');
    $table->enum('status', ['*', '*', '*', '*', '*'])->default('*');

However, this table is already migrated. So what's wrong?

3
  • From the docs: "Only the following column types can be "changed": bigInteger, binary, boolean, date, dateTime, dateTimeTz, decimal, integer, json, longText, mediumText, smallInteger, string, text, time, unsignedBigInteger, unsignedInteger and unsignedSmallInteger." The migration probably fails because it detects the enum fields and then stops working to prevent messing up the database. Also, obligatory anti-enum: komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil Commented May 8, 2018 at 8:25
  • This solution solved my problem: stackoverflow.com/a/42107554/7979661 Commented May 8, 2018 at 9:08
  • Ah nice, didn't know about that! Commented May 8, 2018 at 9:10

1 Answer 1

-1

Try this

    public function up()
{
    //
    Schema::table('events', function($table) {
        $table->string('owner_type')->default(0);
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    //
    Schema::table('events', function($table) {
        $table->dropColumn('owner_type');
    });
}
Sign up to request clarification or add additional context in comments.

Comments

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.