PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, April 13, 2022

[FIXED] How to change enum type column in laravel migration?

 April 13, 2022     enums, laravel, laravel-5.1, migration     No comments   

Issue

I am using Laravel 5.1 and I have a table called packages with this structure:

id              int(11)
weight          decimal(10,2)           
weight_unit     enum('Kg.', 'Gm.')

I would like to change the weight_unit enum to:

weight_unit enum('Grams','Kgs.','Pounds')

For this I create the following migration:

public function up()
{
    Schema::table('packages', function ($table) {
        $table->enum('weight_unit', array('Grams','Kgs.','Pounds'))->nullable()->change();
    });
}

But when I run the migration I receive an error:

Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform  

may not support it.

How can I change this enum?


Solution

Use the DB::statement method:

DB::statement("ALTER TABLE packages MODIFY COLUMN weight_unit ENUM('Grams', 'Kgs', 'Pounds')");


Answered By - Tayyab Hussain
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing