ssquare's avatar

Add value to already existed column in laravel sqlite

I tried this following query to add values to the enum field in laravel:

Schema::table('files', function (Blueprint $table) {
    $table->enum('file_type',['p','sq','pr','ao'])
        ->comment('p => property, sq => square offset or FloorPlan, pr => pricing review, ao => availability_overlay')
        ->change();
});

With above code: it throws erors as:

  Unknown column type "enum" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType()

So, on looking I found I need to use raw query, and here it is:

Schema::table('files', function (Blueprint $table) {
	\DB::statement("
	    ALTER TABLE `files` CHANGE COLUMN `file_type` `file_type` ENUM('p','sq','pr','ao') COMMENT 'p => property, sq => square offset or Floorplan, pr => pricing review, ao => availability_overlay' NOT NULL
	");
});

this one is working fine, but it is not working on test environment (sqlite). How, could I add the equivalent query of above for sqlite environment.

0 likes
2 replies
Nakov's avatar

For the firs error you'll need to install the package composer require doctrine/dbal

and for the second one the issue is that there is no enum type on sqlite: here are some answers https://stackoverflow.com/a/17203007/1457270

What I will usually do is check for the environment in the test itself and use different data type for the test only, and then within the tests you can check for the allowed values, or create a form request that also checks for those values.

ssquare's avatar
  1. I have already installed doctrine/dbal still showing issue,
  2. As I have already mentioned that I am trying to add value on the already existing enum column, so what should I run to add a new value to that enum filed, but they are just showing the options to create another column like varchar instead of enum column, but I have to edit it instead, not create the new on, so could you please help on how could I alter that column for sqlite.

Actually, am trying to run the tests on SQLite, but these migrations are throwing issues like these.

Please or to participate in this conversation.