BigJobbies
BigJobbies

Reputation: 509

Laravel PHPUnit failing on ALTER TABLE using SQLite

I have a migration which I made at the beginning of my project, basically adding a TEXT column called 'description' which is set to NOT NULL.

Now several months down the track I need to change that to allow null.

I can't use Laravel 5.5 change() function as I have a enum in my column list and it bugs out, so i need to add it as a raw query in a migration like so;

DB::statement('ALTER TABLE `galleries` MODIFY `description` TEXT NULL;');

When i do a php artisan migrate against my local mysql database it all works great, BUT when i try to run my test suite, it all breaks.

Im using SQLite for my test suite, and the error im getting is as follows;

PDOException: SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error

If anyone else has come up against this issue and fixed it, i would love to hear how you did it.

Thanks

Upvotes: 5

Views: 4273

Answers (1)

patricus
patricus

Reputation: 62338

SQLite only allows you to rename the table or add a column. The ALTER TABLE statement cannot change or remove columns.

In order to change or remove a column in SQLite, you need to create a new table with the desired schema, copy the data from the original table to the new table, delete the original table, and then rename the new table to the original name.

This is all abstracted out for you by Laravel and DBAL, so your best bet may be to get help with figuring out the issue with your enum column (though that would be a separate question).

You can read more about altering tables in the SQLite docs here.

Upvotes: 8

Related Questions